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

pub static ELLEVIO: GridOperator = GridOperator::builder()
    .name("Ellevio")
    .vat_number("SE556037732601")
    .country(SE)
    .links(
        Links::builder()
            .fee_info_complex(
                "https://www.ellevio.se/abonnemang/elnatspriser/hus/",
                ContentLocator::new_starts_with(
                    "För bland annat villor, radhus, fritidshus och verksamhetslokaler med egen",
                    TargetContainer::Parent,
                    ContentTarget::TextWithLinks,
                ),
            )
            .build(),
    )
    .price_lists(&[
        PriceList::builder()
            .from_date(2025, 1, 1)
            .monthly_fee(Cost::fuses(&[
                (16, Money::new(365, 0)),
                (20, Money::new(365, 0)),
                (25, Money::new(365, 0)),
                (35, Money::new(915, 0)),
                (50, Money::new(1400, 0)),
                (63, Money::new(2010, 0)),
            ]))
            .monthly_production_fee(Cost::None)
            .feed_in_revenue(FEED_IN_REVENUE_STHML_2025)
            .transfer_fee(TransferFee::fixed_subunit(6.25))
            .power_tariff(POWER_TARIFF_2025_2026)
            .build(),
        PriceList::builder()
            .from_date(2026, 1, 1)
            .monthly_fee(Cost::fuses(&[
                (16, Money::new(395, 0)),
                (20, Money::new(395, 0)),
                (25, Money::new(395, 0)),
                (35, Money::new(990, 0)),
                (50, Money::new(1515, 0)),
                (63, Money::new(2175, 0)),
            ]))
            .monthly_production_fee(Cost::None)
            // TODO: Add 2026 once available
            .feed_in_revenue(FEED_IN_REVENUE_STHML_2026)
            .transfer_fee(TransferFee::fixed_subunit(7.0))
            .power_tariff(POWER_TARIFF_2025_2026)
            .build(),
    ])
    .build();

const POWER_TARIFF_2025_2026: PowerTariff = PowerTariff::new(
    TariffCalculationMethod::AverageDays(3),
    CostPeriods::new_first(&[CostPeriod::builder()
        .load(Base)
        .cost(Cost::fixed(81, 25))
        .build()]),
)
.add_power_divide(PowerDivide::new(Some(Hours::new(22, 5, Stockholm)), 2));

// TODO: We need to add support per Nätprisområde (Stockholm, Västkusten + 2 more)
//       Issue: https://git.spotpilot.io/spotpilot/grid-tariffs/issues/445
static FEED_IN_REVENUE_STHML_2025: FeedInRevenue =
    FeedInRevenue::new_periods(CostPeriods::new_first(&[
        CostPeriod::builder()
            .load(High)
            .hours(6, 21)
            .months(November, March)
            .exclude_weekends()
            .exclude_holidays(SE)
            .fixed_cost_subunit(5.2)
            .build(),
        CostPeriod::builder()
            .load(Low)
            .fixed_cost_subunit(4.1)
            .build(),
    ]));

// TODO: We need to add support per Nätprisområde (Stockholm, Västkusten + 2 more)
//       Issue: https://git.spotpilot.io/spotpilot/grid-tariffs/issues/445
static FEED_IN_REVENUE_STHML_2026: FeedInRevenue =
    FeedInRevenue::new_periods(CostPeriods::new_first(&[
        CostPeriod::builder()
            .load(High)
            .hours(6, 21)
            .months(November, March)
            .exclude_weekends()
            .exclude_holidays(SE)
            .fixed_cost_subunit(4.4)
            .build(),
        CostPeriod::builder()
            .load(Low)
            .fixed_cost_subunit(3.3)
            .build(),
    ]));
