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

static FEE_LINK: &str = "https://www.goteborgenergi.se/privat/elnat/elnatsavgiften";
static FEED_IN_LINK: &str = "https://www.goteborgenergi.se/foretag/elnat/egenproducerad-el";
static ELTARIFF_API_LINK: &str = "https://api.goteborgenergi.cloud/gridtariff/v0/tariffs";

const LINKS: Links = Links::builder()
    .fee_info(FEE_LINK, "#prisvilla + *")
    .feed_in_revenue_info_default(FEED_IN_LINK)
    .eltariff_api(ELTARIFF_API_LINK)
    .build();

const PRICELIST_BASE: PriceListBuilder = PriceListBuilder::new()
    .monthly_production_fee(Cost::None)
    .feed_in_revenue(FeedInRevenue::fixed_subunit(7.0));

const ENERGY_BASED_PRICELIST_BASE: PriceListBuilder = PRICELIST_BASE
    .from_date(2025, 1, 1)
    .transfer_fee(TransferFee::fixed_subunit(7.5))
    .power_tariff(PowerTariff::new(
        TariffCalculationMethod::AverageDays(3),
        CostPeriods::new_first(&[
            CostPeriod::builder()
                .load(High)
                // TODO: Handling of summer time counting as winter time
                //       See https://git.spotpilot.io/spotpilot/grid-tariffs/issues/195
                .hours(7, 20)
                .months(November, March)
                .exclude_weekends()
                .exclude_holidays(SE)
                .fixed_cost(132, 0)
                .build(),
            CostPeriod::builder().load(Low).cost(Cost::None).build(),
        ]),
    ));

pub static GOTEBORG_ENERGI: GridOperator = GridOperator::builder()
    .name("Göteborg Energi")
    .vat_number("SE556379272901")
    .country(SE)
    .links(LINKS)
    .price_lists(&[
        PRICELIST_BASE
            .variant("Standard")
            .from_date(2025, 1, 1)
            .monthly_fee(Cost::fixed(185, 0))
            .transfer_fee(TransferFee::fixed_subunit(25.))
            .power_tariff(PowerTariff::new(
                TariffCalculationMethod::AverageDays(3),
                CostPeriods::new_first(&[CostPeriod::builder()
                    .load(Base)
                    .fixed_cost(45, 0)
                    .build()]),
            ))
            .build(),
        ENERGY_BASED_PRICELIST_BASE
            .variant("Tidsbaserad, 6 kW")
            .monthly_fee(Cost::fixed(182, 50))
            .build(),
        ENERGY_BASED_PRICELIST_BASE
            .variant("Tidsbaserad, 14 kW")
            .monthly_fee(Cost::fixed(342, 50))
            .build(),
        ENERGY_BASED_PRICELIST_BASE
            .variant("Tidsbaserad, 43 kW")
            .monthly_fee(Cost::fixed(927, 50))
            .build(),
    ])
    .build();
