export type CqcKey = "Safe" | "Effective" | "Caring" | "Responsive" | "Well-led";
export type AuditStatus = "completed" | "overdue" | "due-soon" | "not-due";

export type AuditItem = {
  id: number;
  department: string;
  name: string;
  frequency: string;
  cqc: CqcKey;
  status: AuditStatus;
  due: string;
  score?: number;
  draft?: boolean;
};

const rows: Array<[string, string, string, CqcKey]> = [
  ["Care & clinical", "Care plans, risk assessments and daily records - representative sample", "Monthly", "Responsive"],
  ["Care & clinical", "New admission: assessment, care plan, consent, risks and first-week review", "Within 7 days of admission", "Effective"],
  ["Care & clinical", "Capacity, consent, best-interest decisions and DoLS", "Monthly", "Responsive"],
  ["Care & clinical", "Personal emergency evacuation plans (PEEPs)", "Monthly", "Safe"],
  ["Care & clinical", "Falls and mobility analysis", "Monthly", "Safe"],
  ["Care & clinical", "Accidents/incidents, trends and lessons learned", "Monthly", "Safe"],
  ["Care & clinical", "Pressure-area care and skin integrity", "Monthly", "Effective"],
  ["Care & clinical", "Wound care records and escalation", "Monthly", "Effective"],
  ["Care & clinical", "Nutrition, weight loss, MUST scores and food/fluid charts", "Monthly", "Effective"],
  ["Care & clinical", "Hydration and dehydration risks", "Monthly", "Effective"],
  ["Care & clinical", "Health appointments, referrals and professional recommendations", "Monthly", "Effective"],
  ["Care & clinical", "End-of-life and anticipatory-care records, where applicable", "Monthly", "Caring"],
  ["Care & clinical", "Dignity, privacy, choice and person-centred care observations", "Monthly", "Caring"],
  ["Medicines", "MAR chart completeness and administration errors/omissions", "Weekly", "Safe"],
  ["Medicines", "Full medicines audit: MARs, stock, ordering, storage, PRN, allergies, creams, patches and expiry dates", "Monthly", "Safe"],
  ["Medicines", "Controlled drugs: balance, records, storage and witnessing", "Weekly", "Safe"],
  ["Medicines", "Medication competency observations", "Annually", "Safe"],
  ["Medicines", "Medication incidents and learning", "Monthly", "Well-led"],
  ["Infection prevention", "IPC: hand hygiene, PPE, waste, cleaning, laundry and equipment", "Monthly", "Safe"],
  ["Infection prevention", "Cleaning schedules and infection/outbreak actions", "Weekly", "Safe"],
  ["Infection prevention", "Sharps management and clinical-waste arrangements", "Monthly", "Safe"],
  ["Catering", "Food safety and kitchen hygiene", "Monthly", "Safe"],
  ["Catering", "Fridge/freezer temperature records and food storage", "Weekly", "Safe"],
  ["Catering", "Meal experience, choice, special diets and allergens", "Monthly", "Caring"],
  ["Catering", "Food/fluid intake charts and meal support", "Monthly", "Effective"],
  ["Housekeeping & laundry", "Laundry segregation, cleanliness, sluice arrangements and chemicals", "Monthly", "Safe"],
  ["Housekeeping & laundry", "COSHH products, data sheets, storage and staff knowledge", "Quarterly", "Safe"],
  ["Activities & wellbeing", "Activities offered, attendance, resident feedback and individual engagement", "Monthly", "Responsive"],
  ["Activities & wellbeing", "Meaningful activity plans for people at risk of isolation", "Monthly", "Caring"],
  ["Safeguarding", "Safeguarding concerns, referrals, outcomes and learning", "Monthly", "Safe"],
  ["Safeguarding", "Restrictive practice, restraint and unexplained injuries", "Monthly", "Safe"],
  ["Complaints & feedback", "Complaints, compliments, response times and learning", "Monthly", "Responsive"],
  ["Complaints & feedback", "Resident meetings and satisfaction feedback", "Quarterly", "Caring"],
  ["Complaints & feedback", "Relative/family feedback", "Quarterly", "Responsive"],
  ["Staffing & HR", "Safe staffing, dependency, rota gaps, agency use and skill mix", "Weekly", "Safe"],
  ["Staffing & HR", "Recruitment files: DBS, references, right to work and employment history", "Monthly", "Safe"],
  ["Staffing & HR", "Training compliance, competencies and refresher dates", "Monthly", "Effective"],
  ["Staffing & HR", "Supervisions, appraisals and probation reviews", "Monthly", "Well-led"],
  ["Staffing & HR", "Sickness, absence, return-to-work and wellbeing", "Monthly", "Well-led"],
  ["Staffing & HR", "Staff files, professional registrations and vaccinations where applicable", "Quarterly", "Well-led"],
  ["Health & safety", "Premises/environment: bedrooms, bathrooms, communal areas, call bells and hazards", "Monthly", "Safe"],
  ["Health & safety", "Fire safety records, fire doors, escape routes and PEEPs", "Monthly", "Safe"],
  ["Health & safety", "Equipment: hoists, slings, wheelchairs, beds, sensors and moving/handling equipment", "Monthly", "Safe"],
  ["Health & safety", "Maintenance log, defects, contractor works and completion of actions", "Monthly", "Safe"],
  ["Health & safety", "Water safety / legionella records and actions", "Monthly", "Safe"],
  ["Health & safety", "Security, visitor signing-in, keys and access control", "Monthly", "Safe"],
  ["Governance", "CQC notifications, statutory notifications and regulatory correspondence", "Monthly", "Well-led"],
  ["Governance", "Policies: version control, staff-read acknowledgements and review dates", "Quarterly", "Well-led"],
  ["Governance", "Audit action plans: overdue actions, evidence and effectiveness checks", "Monthly", "Well-led"],
  ["Governance", "Provider/management quality report: themes, risks, feedback and improvements", "Quarterly", "Well-led"],
  ["Governance", "Business continuity, emergency planning and evacuation arrangements", "Annually", "Well-led"],
  ["Governance", "Statement of Purpose, service capacity, fees, insurance and registration details", "Annually", "Well-led"],
  ["Finance & admin", "Resident contracts, funding, deposits, fee reviews and invoicing", "Monthly", "Well-led"],
  ["Data protection", "Confidentiality, PCS access, records storage and data breaches", "Quarterly", "Well-led"],
];

const statusPlan: AuditStatus[] = rows.map((_, index) =>
  index < 18 ? "completed" : index < 22 ? "overdue" : index < 28 ? "due-soon" : "not-due"
);

export const audits: AuditItem[] = rows.map((row, index) => ({
  id: index + 1,
  department: row[0],
  name: row[1],
  frequency: row[2],
  cqc: row[3],
  status: statusPlan[index],
  due: statusPlan[index] === "completed" ? "Completed" : statusPlan[index] === "overdue" ? "2 Aug 2026" : statusPlan[index] === "due-soon" ? "14 Aug 2026" : "1 Sep 2026",
  score: statusPlan[index] === "completed" ? [80, 76, 68, 80, 72, 60][index % 6] : undefined,
}));

export const frequencies = ["Daily", "Weekly", "Monthly", "Quarterly", "Six-monthly", "Annually", "Within 7 days of admission"];
export const cqcKeys: CqcKey[] = ["Safe", "Effective", "Caring", "Responsive", "Well-led"];
