export type FilterField =
  | "address"
  | "postcode"
  | "currentEpc"
  | "expectedEpc"
  | "lodgedEpc"
  | "epcExpiryDate"
  | "propertyRef"
  | "propertyType"
  | "builtForm"
  | "tenure"
  | "yearBuilt"
  | "floorArea"
  | "co2Emissions"
  | "mainfuel";

export type FilterOperator =
  | "contains"
  | "starts_with"
  | "equals"
  | "epc_at_least"
  | "epc_at_most"
  | "epc_less_than"
  | "epc_greater_than"
  | "epc_one_of"
  | "date_before"
  | "date_after"
  | "date_equals"
  | "date_preset"
  | "enum_one_of"
  | "num_gte"
  | "num_lte"
  | "num_equals";

export type DatePreset =
  | "expired"
  | "expires_this_year"
  | "expires_within_1_year"
  | "expires_within_2_years";

export interface PropertyFilter {
  id: string;
  field: FilterField;
  operator: FilterOperator;
  value: string;
}

export interface FilterGroup {
  id: string;
  conditions: PropertyFilter[];
}

export type FilterGroups = FilterGroup[];

/* -----------------------------------------------------------------------
   Enum option definitions for categorical filter fields
------------------------------------------------------------------------ */

export interface EnumOption {
  /** User-facing display label */
  label: string;
  /** Actual DB values to match. Use ["__null__"] to match NULL. */
  dbValues: string[];
}

export const PROPERTY_TYPE_OPTIONS: EnumOption[] = [
  { label: "House",       dbValues: ["House"] },
  { label: "Flat",        dbValues: ["Flat"] },
  { label: "Bungalow",    dbValues: ["Bungalow"] },
  { label: "Maisonette",  dbValues: ["Maisonette"] },
];

export const BUILT_FORM_OPTIONS: EnumOption[] = [
  { label: "Detached",              dbValues: ["Detached"] },
  { label: "Semi-Detached",         dbValues: ["Semi-Detached"] },
  { label: "End-Terrace",           dbValues: ["End-Terrace"] },
  { label: "Mid-Terrace",           dbValues: ["Mid-Terrace"] },
  { label: "Enclosed End-Terrace",  dbValues: ["Enclosed End-Terrace"] },
  { label: "Enclosed Mid-Terrace",  dbValues: ["Enclosed Mid-Terrace"] },
  { label: "Not Recorded",          dbValues: ["Not Recorded"] },
];

export const TENURE_OPTIONS: EnumOption[] = [
  { label: "Owner-occupied",   dbValues: ["Owner-occupied", "owner-occupied"] },
  { label: "Rented (Private)", dbValues: ["Rented (private)", "rental (private)", "rented (private)"] },
  { label: "Rented (Social)",  dbValues: ["Rented (social)", "rental (social)"] },
  { label: "Not Defined",      dbValues: ["Not defined - use in the case of a new dwelling for which the intended tenure in not known. It is not to be used for an existing dwelling"] },
  { label: "Unknown",          dbValues: ["unknown"] },
  { label: "Not Recorded",     dbValues: ["__null__"] },
];

export const YEAR_BUILT_OPTIONS: EnumOption[] = [
  "1900","1930","1950","1967","1976","1983","1991","1996",
  "2003","2007","2008","2009","2010","2011","2012","2013",
  "2014","2015","2016","2017","2018","2019","2020","2021",
  "2022","2023","2024","2025",
].map((y) => ({ label: y, dbValues: [y] }));

export const MAINFUEL_OPTIONS: EnumOption[] = [
  { label: "Mains Gas",                    dbValues: ["Gas mains gas", "Mains gas community", "Mains gas not community", "Mains gas this is for backwards compatibility only and should not be used"] },
  { label: "LPG",                          dbValues: ["Bottled lpg", "Lpg community", "Lpg not community", "Lpg this is for backwards compatibility only and should not be used"] },
  { label: "Oil",                          dbValues: ["Oil heating oil", "Oil community", "Oil not community", "Oil this is for backwards compatibility only and should not be used"] },
  { label: "Electricity",                  dbValues: ["Electricity electricity unspecified tariff", "Electricity community", "Electricity not community", "Electricity this is for backwards compatibility only and should not be used"] },
  { label: "Biomass",                      dbValues: ["Bulk wood pellets", "Wood chips", "Wood logs", "Biomass community", "Biomass this is for backwards compatibility only and should not be used"] },
  { label: "Coal",                         dbValues: ["Anthracite", "House coal not community", "House coal this is for backwards compatibility only and should not be used", "Smokeless coal", "Coal community"] },
  { label: "Dual Fuel (Mineral + Wood)",   dbValues: ["Dual fuel mineral wood"] },
  { label: "Biogas",                       dbValues: ["Biogas not community"] },
  { label: "Biodiesel",                    dbValues: ["Heat from boilers using biodiesel from any biomass source community"] },
  { label: "B30d (Biodiesel blend)",       dbValues: ["B30d community"] },
  { label: "B30k (Biodiesel blend)",       dbValues: ["B30k not community"] },
  { label: "Community Heat Network",       dbValues: ["From heat network data community"] },
  { label: "No Heating System",            dbValues: ["To be used only when there is no heatinghotwater system", "To be used only when there is no heatinghotwater system or data is from a community network"] },
  { label: "Unknown / No Data",            dbValues: ["UNKNOWN", "NO DATA!"] },
];
