package cn.bunny.pattern9;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.Random;

public class Adapter2 {
    public static void main(String[] args) {
        Power power = new Power();
        PowerAdapter powerAdapter = new PowerAdapter(power);
        Integer integer = powerAdapter.output220V();
    }

    // 电压输出
    interface PowerTarget {
        /**
         * 输出电压220V
         *
         * @return 输出电压
         */
        Integer output220V();
    }

    @Setter
    @Getter
    static class PowerAdapter implements PowerTarget {
        private final Power power;

        public PowerAdapter(Power power) {
            this.power = power;
        }

        /**
         * 输出电压220V
         *
         * @return 输出电压
         */
        @Override
        public Integer output220V() {
            Integer output = power.getOutput();
            System.out.println("变压器交流" + output + "v转220v三相电变两项电。。。");

            double adapter = new Random().nextDouble(1.64, 1.72);
            Integer newOutput = (int) (output / adapter);
            System.out.println("变压器转换完成：电压输出为：" + newOutput);

            return newOutput;
        }

    }

    @Data
    static class Power {
        private Integer output = 380;

        public Integer output380V() {
            System.out.println("输出电压：" + output);
            return output;
        }
    }
}
