# Class DiscountApprovalService

java.lang.Object
com.university.bookstore.chain.DiscountApprovalService

public class DiscountApprovalService extends Object
Service for managing discount approval using the Chain of Responsibility pattern. Builds and manages the approval chain and processes discount requests.

This service demonstrates the Chain of Responsibility pattern by creating a hierarchy of approval handlers and processing requests through the chain.

Since:
  2024-09-15
Version:
  3.0
Author:
  Navid Mohaghegh

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `DiscountApprovalService.ApprovalStats`
  Statistics class for approval analysis.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DiscountApprovalService()`
  Creates a new discount approval service with the default chain.
  `DiscountApprovalService(DiscountHandler chain)`
  Creates a new discount approval service with a custom chain.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `double`
  `calculateFinalPrice(DiscountRequest request)`
  Calculates the final price for an approved discount request.
  `void`
  `clearRequests()`
  Clears all processed requests.
  `DiscountApprovalService.ApprovalStats`
  `getApprovalStats()`
  Gets approval statistics.
  `List<DiscountRequest>`
  `getApprovedRequests()`
  Gets approved discount requests.
  `String`
  `getChainInfo()`
  Gets the approval chain information.
  `List<DiscountRequest>`
  `getProcessedRequests()`
  Gets all processed discount requests.
  `List<DiscountRequest>`
  `getRejectedRequests()`
  Gets rejected discount requests.
  `List<DiscountRequest>`
  `getRequestsForCustomer(String customerId)`
  Gets discount requests for a specific customer.
  `List<DiscountRequest>`
  `getRequestsForMaterial(Material material)`
  Gets discount requests for a specific material.
  `DiscountRequest`
  `requestDiscount(Material material, double discountPercent, String customerId, String reason)`
  Processes a discount request through the approval chain.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### DiscountApprovalService

    public DiscountApprovalService()
    Creates a new discount approval service with the default chain.

  - ### DiscountApprovalService

    public DiscountApprovalService(DiscountHandler chain)
    Creates a new discount approval service with a custom chain.
    Parameters:
      `chain` - the approval chain to use

- ## Method Details

  - ### requestDiscount

    public DiscountRequest requestDiscount(Material material, double discountPercent, String customerId, String reason)
    Processes a discount request through the approval chain.
    Parameters:
      `material` - the material for which discount is requested
      `discountPercent` - the discount percentage (0.0 to 100.0)
      `customerId` - the customer requesting the discount
      `reason` - the reason for the discount request
    Returns:
      the processed discount request

  - ### calculateFinalPrice

    public double calculateFinalPrice(DiscountRequest request)
    Calculates the final price for an approved discount request.
    Parameters:
      `request` - the discount request
    Returns:
      the final price

  - ### getProcessedRequests

    public List<DiscountRequest> getProcessedRequests()
    Gets all processed discount requests.
    Returns:
      list of processed requests

  - ### getApprovedRequests

    public List<DiscountRequest> getApprovedRequests()
    Gets approved discount requests.
    Returns:
      list of approved requests

  - ### getRejectedRequests

    public List<DiscountRequest> getRejectedRequests()
    Gets rejected discount requests.
    Returns:
      list of rejected requests

  - ### getRequestsForCustomer

    public List<DiscountRequest> getRequestsForCustomer(String customerId)
    Gets discount requests for a specific customer.
    Parameters:
      `customerId` - the customer ID
    Returns:
      list of requests for the customer

  - ### getRequestsForMaterial

    public List<DiscountRequest> getRequestsForMaterial(Material material)
    Gets discount requests for a specific material.
    Parameters:
      `material` - the material
    Returns:
      list of requests for the material

  - ### getApprovalStats

    public DiscountApprovalService.ApprovalStats getApprovalStats()
    Gets approval statistics.
    Returns:
      approval statistics

  - ### clearRequests

    public void clearRequests()
    Clears all processed requests.

  - ### getChainInfo

    public String getChainInfo()
    Gets the approval chain information.
    Returns:
      chain information

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`