use crate::registry::prelude::*;

static FEE_LINK: &str = "https://www.vattenfalleldistribution.se/abonnemang-och-avgifter/avtal-och-avgifter/elnatsavgifter/sakringsabonnemang-16-63a/";
static FEED_IN_LINK: &str = "https://www.vattenfalleldistribution.se/elnatsanslutning/anslut-elproduktion/ersattning-egen-el/";

const TRANSFER_FEE_HIGH: CostPeriodBuilder = CostPeriodBuilder::new()
    .load(High)
    .months(November, March)
    .hours(6, 21)
    .exclude_weekends();
const TRANSFER_FEE_LOW: CostPeriodBuilder = CostPeriodBuilder::new().load(Low);
// NOTE: Transfer fee period doesn't exclude holidays!
const FEED_IN_HIGH: CostPeriodBuilder = TRANSFER_FEE_HIGH.exclude_holidays(Country::SE);
const FEED_IN_LOW: CostPeriodBuilder = CostPeriodBuilder::new().load(Low);

const BASE_PRICELIST_2025: PriceListBuilder = PriceListBuilder::new()
    .from_date(2025, 1, 1)
    .monthly_fee(Cost::fuses(&[
        (16, Money::new(420, 83)),
        (20, Money::new(588, 75)),
        (25, Money::new(737, 50)),
        (35, Money::new(1011, 67)),
        (50, Money::new(1452, 50)),
        (63, Money::new(1957, 92)),
    ]))
    .monthly_production_fee(Cost::Unverified)
    .feed_in_revenue(FeedInRevenue::new_periods(CostPeriods::new_first(&[
        FEED_IN_HIGH.fixed_cost_subunit(6.4).build(),
        FEED_IN_LOW.fixed_cost_subunit(13.2).build(),
    ])))
    .power_tariff(PowerTariff::NotImplemented);

const BASE_PRICELIST_2026: PriceListBuilder = PriceListBuilder::new()
    .from_date(2026, 1, 1)
    .monthly_fee(Cost::fuses(&[
        (16, Money::new(5775, 0).divide_by(12)),
        (20, Money::new(8085, 0).divide_by(12)),
        (25, Money::new(10125, 0).divide_by(12)),
        (35, Money::new(13890, 0).divide_by(12)),
        (50, Money::new(19945, 0).divide_by(12)),
        (63, Money::new(26875, 0).divide_by(12)),
    ]))
    .monthly_production_fee(Cost::None)
    .feed_in_revenue(FeedInRevenue::new_periods(CostPeriods::new_first(&[
        FEED_IN_HIGH.fixed_cost_subunit(4.8).build(),
        FEED_IN_LOW.fixed_cost_subunit(10.4).build(),
    ])))
    .power_tariff(PowerTariff::NotImplemented);

pub static VATTENFALL: GridOperator = GridOperator::builder()
    .name("Vattenfall")
    .vat_number("SE556417080001")
    .country(SE)
    .links(
        Links::builder()
            .fee_info_complex(
                FEE_LINK,
                ContentLocator::new_starts_with(
                    "Säkringsabonnemang (16–63 A)",
                    TargetContainer::Ancestor(1),
                    ContentTarget::Attribute("data-content"),
                ),
            )
            .feed_in_revenue_info_default(FEED_IN_LINK)
            .build(),
    )
    .price_lists(&[
        BASE_PRICELIST_2025
            .variant("Enkeltariff E4")
            .transfer_fee(TransferFee::fixed_subunit(39.0))
            .build(),
        BASE_PRICELIST_2025
            .variant("Tidstariff T4")
            .transfer_fee(TransferFee::new_periods(CostPeriods::new_first(&[
                TRANSFER_FEE_HIGH.fixed_cost_subunit(67.00).build(),
                TRANSFER_FEE_LOW.fixed_cost_subunit(26.80).build(),
            ])))
            .build(),
        BASE_PRICELIST_2026
            .variant("Enkeltariff E4")
            .transfer_fee(TransferFee::fixed_subunit(44.5))
            .build(),
        BASE_PRICELIST_2026
            .variant("Tidstariff T4")
            .transfer_fee(TransferFee::new_periods(CostPeriods::new_first(&[
                TRANSFER_FEE_HIGH.fixed_cost_subunit(76.50).build(),
                TRANSFER_FEE_LOW.fixed_cost_subunit(30.50).build(),
            ])))
            .build(),
    ])
    .build();
