use crate::registry::{prelude::*, sweden::tekniska_verken::*};

static FEE_INFO_LINK: &str = "https://www.mse.se/kundservice/priser-och-avtal/priser-elnat-2025/";
static FEED_IN_LINK: &str = "https://www.mse.se/kundservice/priser-och-avtal/ersattning-avgifter-egen-elproduktion-elnat-2025/";

pub static MJOLBY_KRAFTNAT_AB: GridOperator = GridOperator::builder()
    .name("Mjölby Kraftnät AB")
    .vat_number("SE556127926501")
    .country(SE)
    .links(
        Links::builder()
            .fee_info(FEE_INFO_LINK, "#abonnemangspriser")
            .feed_in_revenue_info_default(FEED_IN_LINK)
            .build(),
    )
    .price_lists(&[
        BASE_PRICELIST_2025
            .variant("Standard")
            .transfer_fee(TransferFee::fixed_subunit(18.9))
            .power_tariff(PowerTariff::new(
                TariffCalculationMethod::AverageDays(5),
                CostPeriods::new_first(&[
                    SUMMER.load(Low).fixed_cost(24, 0).build(),
                    WINTER.load(High).fixed_cost(48, 0).build(),
                ]),
            ))
            .build(),
        // TODO: I don't think we support their alternative model
        //       See issue: https://git.spotpilot.io/spotpilot/grid-tariffs/issues/448
        BASE_PRICELIST_2025
            .variant("Alternativ")
            .transfer_fee(TransferFee::new_periods(CostPeriods::new_first(&[
                BASE_BUILDER
                    .include(NIGHT_HOURS)
                    .load(Low)
                    .fixed_cost_subunit(11.5)
                    .build(),
                BASE_BUILDER
                    .include(DAY_HOURS)
                    .load(High)
                    .fixed_cost_subunit(23.0)
                    .build(),
            ])))
            .power_tariff(PowerTariff::new(
                TariffCalculationMethod::AverageDays(1),
                CostPeriods::new_first(&[
                    SUMMER_NIGHTS.load(Low).fixed_cost(8, 0).build(),
                    SUMMER_DAYS.load(High).fixed_cost(24, 0).build(),
                    WINTER_NIGHTS.load(Low).fixed_cost(12, 0).build(),
                    WINTER_DAYS.load(High).fixed_cost(48, 0).build(),
                ]),
            ))
            .build(),
    ])
    .build();

const BASE_PRICELIST_2025: PriceListBuilder = PriceListBuilder::new()
    .from_date(2025, 1, 1)
    .feed_in_revenue(FeedInRevenue::fixed_subunit(4.5))
    .monthly_fee(Cost::fuses(&[
        (16, Money::new(225, 0)),
        (20, Money::new(320, 0)),
        (25, Money::new(400, 0)),
        (35, Money::new(590, 0)),
        (50, Money::new(825, 0)),
        (63, Money::new(1030, 0)),
    ]))
    .monthly_production_fee(Cost::None);
