export type FileType =
  | "folder"
  | "document"
  | "spreadsheet"
  | "image"
  | "video"
  | "pdf"
  | "code"
  | "archive"
  | "audio"
  | "unknown"

export type SharedRole = "viewer" | "editor"

export type SharedUser = {
  name: string
  avatar?: string
  role: SharedRole
}

export type FileOwner = {
  name: string
  avatar?: string
}

export type FileItem = {
  id: string
  name: string
  type: FileType
  mimeType?: string
  size: number
  path: string[]
  createdAt: string
  modifiedAt: string
  owner: FileOwner
  starred: boolean
  shared: boolean
  sharedWith?: SharedUser[]
  trashed: boolean
  parentId: string | null
  webViewLink?: string
}

export type StorageUsage = {
  used: number
  total: number
}

const owner = {
  name: "Martine Vogel",
  avatar: "/avatars/martine.jpg",
}
const pm1 = { name: "Derek Haines" }
const pm2 = { name: "Rachel Torres" }
const field1 = { name: "Mike Callahan" }

// ─── CSI Division folder generator ───

const CSI_DIVISIONS = [
  "00 00 00 Procurement Req",
  "01 00 00 General Req",
  "02 00 00 Ext Conditions",
  "03 00 00 Concrete",
  "04 00 00 Masonry",
  "05 00 00 Metals",
  "06 00 00 Woods Plastics and Composites",
  "07 00 00 Thermal Protection",
  "08 00 00 Openings",
  "09 00 00 Finishes",
  "10 00 00 Specialties",
  "11 00 00 Equipment",
  "12 00 00 Furnishings",
  "13 00 00 Special Const",
  "14 00 00 Conveying Equipment",
  "21 00 00 Fire Suppression",
  "22 00 00 Plumbing",
  "23 00 00 HVAC",
  "26 00 00 Electrical",
  "27 00 00 Communications",
  "28 00 00 Safety and Security",
  "31 00 00 Earthwork",
  "32 00 00 Exterior Improvement",
  "33 00 00 Utilities",
  "48 00 00 Electrical Power Generation Equipment",
] as const

function buildCsiDivisions(
  parentId: string,
  parentPath: string[]
): FileItem[] {
  return CSI_DIVISIONS.map((name) => ({
    id: `${parentId}-csi-${name.slice(0, 2)}`,
    name,
    type: "folder" as FileType,
    size: 0,
    path: parentPath,
    createdAt: "2025-07-15T08:00:00Z",
    modifiedAt: "2025-10-20T14:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm1, role: "editor" as SharedRole }],
    trashed: false,
    parentId,
  }))
}

export const mockFiles: FileItem[] = [
  // ─── Top-level company folders ───
  {
    id: "folder-00-corporate",
    name: "00_Corporate",
    type: "folder",
    size: 0,
    path: [],
    createdAt: "2025-06-01T08:00:00Z",
    modifiedAt: "2026-01-10T09:00:00Z",
    owner,
    starred: false,
    shared: false,
    trashed: false,
    parentId: null,
  },
  {
    id: "folder-01-company-structure",
    name: "01_CompanyStructure",
    type: "folder",
    size: 0,
    path: [],
    createdAt: "2025-06-01T08:00:00Z",
    modifiedAt: "2025-12-15T10:00:00Z",
    owner,
    starred: false,
    shared: false,
    trashed: false,
    parentId: null,
  },
  {
    id: "folder-02-sops",
    name: "02_SOPs",
    type: "folder",
    size: 0,
    path: [],
    createdAt: "2025-06-01T08:00:00Z",
    modifiedAt: "2026-01-05T14:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [
      { ...pm1, role: "viewer" },
      { ...pm2, role: "viewer" },
    ],
    trashed: false,
    parentId: null,
  },
  {
    id: "folder-03-hr",
    name: "03_HumanResources",
    type: "folder",
    size: 0,
    path: [],
    createdAt: "2025-06-01T08:00:00Z",
    modifiedAt: "2025-11-20T16:00:00Z",
    owner,
    starred: false,
    shared: false,
    trashed: false,
    parentId: null,
  },
  {
    id: "folder-04-ar",
    name: "04_AccountsReceivable",
    type: "folder",
    size: 0,
    path: [],
    createdAt: "2025-06-01T08:00:00Z",
    modifiedAt: "2026-01-15T11:00:00Z",
    owner,
    starred: false,
    shared: false,
    trashed: false,
    parentId: null,
  },
  {
    id: "folder-05-ap",
    name: "05_AccountsPayable",
    type: "folder",
    size: 0,
    path: [],
    createdAt: "2025-06-01T08:00:00Z",
    modifiedAt: "2026-01-18T09:30:00Z",
    owner,
    starred: false,
    shared: false,
    trashed: false,
    parentId: null,
  },
  {
    id: "folder-06-licenses",
    name: "06_LicensesRegistrations",
    type: "folder",
    size: 0,
    path: [],
    createdAt: "2025-06-01T08:00:00Z",
    modifiedAt: "2025-09-10T12:00:00Z",
    owner,
    starred: false,
    shared: false,
    trashed: false,
    parentId: null,
  },
  {
    id: "folder-11-nutech",
    name: "11_NuTechProjects",
    type: "folder",
    size: 0,
    path: [],
    createdAt: "2025-06-01T08:00:00Z",
    modifiedAt: "2026-01-20T14:00:00Z",
    owner,
    starred: true,
    shared: true,
    sharedWith: [
      { ...pm1, role: "editor" },
      { ...pm2, role: "editor" },
    ],
    trashed: false,
    parentId: null,
  },
  {
    id: "folder-12-design",
    name: "12_DesignProjects",
    type: "folder",
    size: 0,
    path: [],
    createdAt: "2025-06-01T08:00:00Z",
    modifiedAt: "2025-12-01T10:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm2, role: "editor" }],
    trashed: false,
    parentId: null,
  },
  {
    id: "folder-14-orc",
    name: "14_ORCProjects",
    type: "folder",
    size: 0,
    path: [],
    createdAt: "2025-06-01T08:00:00Z",
    modifiedAt: "2026-01-22T16:00:00Z",
    owner,
    starred: true,
    shared: true,
    sharedWith: [
      { ...pm1, role: "editor" },
      { ...pm2, role: "editor" },
      { ...field1, role: "viewer" },
    ],
    trashed: false,
    parentId: null,
  },

  // ─── 03_HumanResources contents ───
  {
    id: "folder-hr-employee",
    name: "00_Employee",
    type: "folder",
    size: 0,
    path: ["03_HumanResources"],
    createdAt: "2025-06-01T08:00:00Z",
    modifiedAt: "2025-11-20T16:00:00Z",
    owner,
    starred: false,
    shared: false,
    trashed: false,
    parentId: "folder-03-hr",
  },

  // ─── 11_NuTechProjects: sample project ───
  {
    id: "folder-nutech-001",
    name: "N-001-1234-Johnson",
    type: "folder",
    size: 0,
    path: ["11_NuTechProjects"],
    createdAt: "2025-08-15T09:00:00Z",
    modifiedAt: "2026-01-20T14:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm1, role: "editor" }],
    trashed: false,
    parentId: "folder-11-nutech",
  },
  {
    id: "folder-nutech-002",
    name: "N-002-5600-Martinez",
    type: "folder",
    size: 0,
    path: ["11_NuTechProjects"],
    createdAt: "2025-10-01T10:00:00Z",
    modifiedAt: "2026-01-18T11:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm2, role: "editor" }],
    trashed: false,
    parentId: "folder-11-nutech",
  },

  // ─── 14_ORCProjects: sample project ───
  {
    id: "folder-orc-001",
    name: "O-001-5678-Williams",
    type: "folder",
    size: 0,
    path: ["14_ORCProjects"],
    createdAt: "2025-07-10T08:00:00Z",
    modifiedAt: "2026-01-22T16:00:00Z",
    owner,
    starred: true,
    shared: true,
    sharedWith: [
      { ...pm1, role: "editor" },
      { ...field1, role: "viewer" },
    ],
    trashed: false,
    parentId: "folder-14-orc",
  },
  {
    id: "folder-orc-002",
    name: "O-002-9012-Chen",
    type: "folder",
    size: 0,
    path: ["14_ORCProjects"],
    createdAt: "2025-09-20T09:00:00Z",
    modifiedAt: "2026-01-15T13:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm2, role: "editor" }],
    trashed: false,
    parentId: "folder-14-orc",
  },

  // ─── O-001-5678-Williams subfolders ───
  {
    id: "folder-orc001-estimate",
    name: "02_WorkingEstimate",
    type: "folder",
    size: 0,
    path: ["14_ORCProjects", "O-001-5678-Williams"],
    createdAt: "2025-07-10T08:00:00Z",
    modifiedAt: "2026-01-10T15:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm1, role: "editor" }],
    trashed: false,
    parentId: "folder-orc-001",
  },
  {
    id: "folder-orc001-payrequests",
    name: "03_PayRequests",
    type: "folder",
    size: 0,
    path: ["14_ORCProjects", "O-001-5678-Williams"],
    createdAt: "2025-07-10T08:00:00Z",
    modifiedAt: "2026-01-20T10:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm1, role: "editor" }],
    trashed: false,
    parentId: "folder-orc-001",
  },
  {
    id: "folder-orc001-constructionlog",
    name: "07_ConstructionLog",
    type: "folder",
    size: 0,
    path: ["14_ORCProjects", "O-001-5678-Williams"],
    createdAt: "2025-07-10T08:00:00Z",
    modifiedAt: "2026-01-22T08:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...field1, role: "editor" }],
    trashed: false,
    parentId: "folder-orc-001",
  },
  {
    id: "folder-orc001-precon",
    name: "10_Preconstruction",
    type: "folder",
    size: 0,
    path: ["14_ORCProjects", "O-001-5678-Williams"],
    createdAt: "2025-07-10T08:00:00Z",
    modifiedAt: "2025-12-15T14:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm1, role: "editor" }],
    trashed: false,
    parentId: "folder-orc-001",
  },

  // ─── 03_PayRequests: sample pay app ───
  {
    id: "folder-orc001-payapp1",
    name: "PayApplication-01-December-2025",
    type: "folder",
    size: 0,
    path: [
      "14_ORCProjects",
      "O-001-5678-Williams",
      "03_PayRequests",
    ],
    createdAt: "2025-12-01T09:00:00Z",
    modifiedAt: "2025-12-15T16:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm1, role: "editor" }],
    trashed: false,
    parentId: "folder-orc001-payrequests",
  },
  {
    id: "folder-orc001-payapp2",
    name: "PayApplication-02-January-2026",
    type: "folder",
    size: 0,
    path: [
      "14_ORCProjects",
      "O-001-5678-Williams",
      "03_PayRequests",
    ],
    createdAt: "2026-01-02T09:00:00Z",
    modifiedAt: "2026-01-20T10:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm1, role: "editor" }],
    trashed: false,
    parentId: "folder-orc001-payrequests",
  },

  // ─── 10_Preconstruction subfolders ───
  {
    id: "folder-orc001-designs",
    name: "01_WorkingDesigns",
    type: "folder",
    size: 0,
    path: [
      "14_ORCProjects",
      "O-001-5678-Williams",
      "10_Preconstruction",
    ],
    createdAt: "2025-07-10T08:00:00Z",
    modifiedAt: "2025-11-20T11:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm1, role: "editor" }],
    trashed: false,
    parentId: "folder-orc001-precon",
  },
  {
    id: "folder-orc001-estimates",
    name: "04_PreconstructionEstimates",
    type: "folder",
    size: 0,
    path: [
      "14_ORCProjects",
      "O-001-5678-Williams",
      "10_Preconstruction",
    ],
    createdAt: "2025-07-10T08:00:00Z",
    modifiedAt: "2025-12-15T14:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm1, role: "editor" }],
    trashed: false,
    parentId: "folder-orc001-precon",
  },

  // ─── Estimate version 00 (CSI divisions) ───
  {
    id: "folder-est-v00",
    name: "O-001-5678-00",
    type: "folder",
    size: 0,
    path: [
      "14_ORCProjects",
      "O-001-5678-Williams",
      "10_Preconstruction",
      "04_PreconstructionEstimates",
    ],
    createdAt: "2025-07-15T08:00:00Z",
    modifiedAt: "2025-10-20T14:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm1, role: "editor" }],
    trashed: false,
    parentId: "folder-orc001-estimates",
  },
  {
    id: "folder-est-v01",
    name: "O-001-5678-01",
    type: "folder",
    size: 0,
    path: [
      "14_ORCProjects",
      "O-001-5678-Williams",
      "10_Preconstruction",
      "04_PreconstructionEstimates",
    ],
    createdAt: "2025-10-25T09:00:00Z",
    modifiedAt: "2025-12-15T14:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm1, role: "editor" }],
    trashed: false,
    parentId: "folder-orc001-estimates",
  },

  // ─── CSI division folders inside estimate v00 ───
  ...buildCsiDivisions("folder-est-v00", [
    "14_ORCProjects",
    "O-001-5678-Williams",
    "10_Preconstruction",
    "04_PreconstructionEstimates",
    "O-001-5678-00",
  ]),

  // ─── Sample files scattered throughout ───
  {
    id: "file-corp-insurance",
    name: "General Liability Policy 2026.pdf",
    type: "pdf",
    mimeType: "application/pdf",
    size: 2_400_000,
    path: ["00_Corporate"],
    createdAt: "2025-12-20T10:00:00Z",
    modifiedAt: "2025-12-20T10:00:00Z",
    owner,
    starred: false,
    shared: false,
    trashed: false,
    parentId: "folder-00-corporate",
  },
  {
    id: "file-sop-safety",
    name: "Safety Protocol v3.pdf",
    type: "pdf",
    mimeType: "application/pdf",
    size: 890_000,
    path: ["02_SOPs"],
    createdAt: "2025-09-01T08:00:00Z",
    modifiedAt: "2026-01-05T14:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [
      { ...pm1, role: "viewer" },
      { ...field1, role: "viewer" },
    ],
    trashed: false,
    parentId: "folder-02-sops",
  },
  {
    id: "file-sop-closeout",
    name: "Project Closeout Checklist.docx",
    type: "document",
    mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    size: 145_000,
    path: ["02_SOPs"],
    createdAt: "2025-07-15T10:00:00Z",
    modifiedAt: "2025-11-10T09:00:00Z",
    owner,
    starred: false,
    shared: true,
    sharedWith: [{ ...pm2, role: "viewer" }],
    trashed: false,
    parentId: "folder-02-sops",
  },
  {
    id: "file-license-gc",
    name: "GC License - State.pdf",
    type: "pdf",
    mimeType: "application/pdf",
    size: 520_000,
    path: ["06_LicensesRegistrations"],
    createdAt: "2025-03-01T08:00:00Z",
    modifiedAt: "2025-03-01T08:00:00Z",
    owner,
    starred: false,
    shared: false,
    trashed: false,
    parentId: "folder-06-licenses",
  },
  {
    id: "file-orc001-estimate-v00",
    name: "Working Estimate v0.xlsx",
    type: "spreadsheet",
    mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    size: 1_200_000,
    path: ["14_ORCProjects", "O-001-5678-Williams", "02_WorkingEstimate"],
    createdAt: "2025-08-01T10:00:00Z",
    modifiedAt: "2026-01-10T15:00:00Z",
    owner: pm1,
    starred: false,
    shared: true,
    sharedWith: [{ ...owner, role: "editor" }],
    trashed: false,
    parentId: "folder-orc001-estimate",
  },
  {
    id: "file-orc001-log-jan",
    name: "Daily Log 2026-01-22.pdf",
    type: "pdf",
    mimeType: "application/pdf",
    size: 340_000,
    path: [
      "14_ORCProjects",
      "O-001-5678-Williams",
      "07_ConstructionLog",
    ],
    createdAt: "2026-01-22T17:00:00Z",
    modifiedAt: "2026-01-22T17:00:00Z",
    owner: field1,
    starred: false,
    shared: true,
    sharedWith: [{ ...owner, role: "viewer" }],
    trashed: false,
    parentId: "folder-orc001-constructionlog",
  },
  {
    id: "file-orc001-floorplan",
    name: "Floor Plan Rev C.pdf",
    type: "pdf",
    mimeType: "application/pdf",
    size: 8_900_000,
    path: [
      "14_ORCProjects",
      "O-001-5678-Williams",
      "10_Preconstruction",
      "01_WorkingDesigns",
    ],
    createdAt: "2025-09-15T14:00:00Z",
    modifiedAt: "2025-11-20T11:00:00Z",
    owner: pm1,
    starred: true,
    shared: true,
    sharedWith: [{ ...owner, role: "editor" }],
    trashed: false,
    parentId: "folder-orc001-designs",
  },
  {
    id: "file-orc001-elevations",
    name: "Elevations Rev B.pdf",
    type: "pdf",
    mimeType: "application/pdf",
    size: 6_200_000,
    path: [
      "14_ORCProjects",
      "O-001-5678-Williams",
      "10_Preconstruction",
      "01_WorkingDesigns",
    ],
    createdAt: "2025-09-15T14:30:00Z",
    modifiedAt: "2025-10-28T09:00:00Z",
    owner: pm1,
    starred: false,
    shared: true,
    sharedWith: [{ ...owner, role: "editor" }],
    trashed: false,
    parentId: "folder-orc001-designs",
  },
  {
    id: "file-payapp1-invoice",
    name: "Invoice-Dec-2025.pdf",
    type: "pdf",
    mimeType: "application/pdf",
    size: 450_000,
    path: [
      "14_ORCProjects",
      "O-001-5678-Williams",
      "03_PayRequests",
      "PayApplication-01-December-2025",
    ],
    createdAt: "2025-12-10T14:00:00Z",
    modifiedAt: "2025-12-15T16:00:00Z",
    owner: pm1,
    starred: false,
    shared: true,
    sharedWith: [{ ...owner, role: "editor" }],
    trashed: false,
    parentId: "folder-orc001-payapp1",
  },
]

export const mockStorageUsage: StorageUsage = {
  used: 156_000_000,
  total: 5_000_000_000,
}
