package com.greenorange.promotion.draft;

// 价格接口
interface Price {
    double getPrice(double price);  // 获取最终报价
}

// 策略抽象类
abstract class Strategy {
    protected Price priceStrategy;

    public Strategy(Price priceStrategy) {
        this.priceStrategy = priceStrategy;
    }

    public abstract double calculatePrice(double price);
}

// 普通用户（全价）
class NormalCustomer extends Strategy {
    public NormalCustomer() {
        super(price -> price); // 全价策略
    }

    @Override
    public double calculatePrice(double price) {
        return priceStrategy.getPrice(price); // 返回全价
    }
}

// 老客户（5%折扣）
class OldCustomer extends Strategy {
    public OldCustomer() {
        super(price -> price * 0.95); // 5%折扣
    }

    @Override
    public double calculatePrice(double price) {
        return priceStrategy.getPrice(price); // 应用折扣
    }
}

class BigCustomer extends Strategy {
    public BigCustomer() {
        super(price -> price * 0.90); // 10%折扣
    }

    @Override
    public double calculatePrice(double price) {
        return priceStrategy.getPrice(price); // 应用折扣
    }
}

// 报价管理类
class PricingManager {
    private Strategy strategy;

    // 设置不同客户的策略
    public void setStrategy(Strategy strategy) {
        this.strategy = strategy;
    }

    // 计算报价
    public double getFinalPrice(double price) {
        return strategy.calculatePrice(price);
    }
}

// 测试类
public class PricingTest {
    public static void main(String[] args) {
        PricingManager pricingManager = new PricingManager();

        // 测试不同客户的价格
        pricingManager.setStrategy(new NormalCustomer());  // 普通用户
        System.out.println("普通用户报价: " + pricingManager.getFinalPrice(1000));

        pricingManager.setStrategy(new OldCustomer());    // 老客户
        System.out.println("老客户报价: " + pricingManager.getFinalPrice(1000));

        pricingManager.setStrategy(new BigCustomer());    // 大客户
        System.out.println("大客户报价: " + pricingManager.getFinalPrice(1000));
    }
}
