import bcrypt from "bcryptjs";
import { roles, transactionStatus, applicationStatus } from "../utils/constants.js";
import { calculateTax } from "./tax.service.js";

const password = bcrypt.hashSync("admin123", 10);

export const users = [
  {
    id: 1,
    name: "Super Admin",
    email: "admin@enotary.gov",
    password_hash: password,
    role: roles.SUPER_ADMIN,
    notary_id: null
  },
  {
    id: 2,
    name: "Justice Officer",
    email: "justice@enotary.gov",
    password_hash: bcrypt.hashSync("justice123", 10),
    role: roles.MINISTRY_JUSTICE,
    notary_id: null
  },
  {
    id: 3,
    name: "Finance Officer",
    email: "finance@enotary.gov",
    password_hash: bcrypt.hashSync("finance123", 10),
    role: roles.MINISTRY_FINANCE,
    notary_id: null
  },
  {
    id: 4,
    name: "Ahmed Owner",
    email: "owner@notary.so",
    password_hash: bcrypt.hashSync("owner123", 10),
    role: roles.OWNER,
    notary_id: 1
  },
  {
    id: 5,
    name: "Teller One",
    email: "teller@notary.so",
    password_hash: bcrypt.hashSync("teller123", 10),
    role: roles.TELLER,
    notary_id: 1
  },
  {
    id: 6,
    name: "Payment One",
    email: "payment@notary.so",
    password_hash: bcrypt.hashSync("payment123", 10),
    role: roles.PAYMENT,
    notary_id: 1
  },
  {
    id: 7,
    name: "Executive One",
    email: "executive@notary.so",
    password_hash: bcrypt.hashSync("exec123", 10),
    role: roles.EXECUTIVE,
    notary_id: 1
  }
];

export const notaryApplications = [
  {
    id: 1,
    name: "Mogadishu Central Notary",
    region: "Banaadir",
    district: "Hodan",
    category: "A",
    license_file: "uploads/license-1.pdf",
    status: applicationStatus.ACTIVE,
    created_at: "2026-04-21T09:00:00Z"
  },
  {
    id: 2,
    name: "Garowe Legal Office",
    region: "Nugaal",
    district: "Garowe",
    category: "B",
    license_file: "uploads/license-2.pdf",
    status: applicationStatus.PENDING,
    created_at: "2026-04-24T08:30:00Z"
  }
];

export const notaries = [
  {
    id: 1,
    name: "Mogadishu Central Notary",
    region: "Banaadir",
    district: "Hodan",
    category: "A",
    owner_user_id: 4,
    status: applicationStatus.ACTIVE
  }
];

const makeTransaction = (seed) => {
  const tax = calculateTax(seed.type, seed.asset_type, seed.amount);
  return {
    ...seed,
    tax_amount: tax,
    total_amount: Number((seed.amount + tax).toFixed(2))
  };
};

export const transactions = [
  makeTransaction({
    id: 1001,
    notary_id: 1,
    type: "sale",
    asset_type: "land",
    client_name: "Khadra Hussein",
    amount: 7515,
    details: { parcel_no: "BN-320", notes: "Urban land sale" },
    status: transactionStatus.COMPLETED,
    created_by: 5,
    approved_by: 7,
    created_at: "2026-04-23T08:30:00Z"
  }),
  makeTransaction({
    id: 1002,
    notary_id: 1,
    type: "investment",
    asset_type: "general",
    client_name: "Bashir Ventures",
    amount: 54000,
    details: { sector: "Port services" },
    status: transactionStatus.COMPLETED,
    created_by: 5,
    approved_by: 7,
    created_at: "2026-04-23T10:10:00Z"
  }),
  makeTransaction({
    id: 1003,
    notary_id: 1,
    type: "evidence",
    asset_type: "general",
    client_name: "Said Farah",
    amount: 0,
    details: { subject: "Identity attestation" },
    status: transactionStatus.COMPLETED,
    created_by: 5,
    approved_by: 7,
    created_at: "2026-04-23T11:00:00Z"
  }),
  makeTransaction({
    id: 1004,
    notary_id: 1,
    type: "agreement",
    asset_type: "general",
    client_name: "Ayaan Ali",
    amount: 1200,
    details: { subject: "Service agreement" },
    status: transactionStatus.PAID,
    created_by: 5,
    approved_by: null,
    created_at: "2026-04-24T07:45:00Z"
  }),
  makeTransaction({
    id: 1005,
    notary_id: 1,
    type: "power_of_attorney",
    asset_type: "general",
    client_name: "Abdi Noor",
    amount: 0,
    details: { represented_by: "Hodan Osman" },
    status: transactionStatus.PENDING,
    created_by: 5,
    approved_by: null,
    created_at: "2026-04-24T08:15:00Z"
  })
];

export const payments = transactions
  .filter((item) => item.status !== transactionStatus.PENDING)
  .map((item, index) => ({
    id: index + 1,
    transaction_id: item.id,
    total: item.total_amount,
    reference_number: `REF-${item.id}`,
    phone: "252612345678",
    paid_at: item.created_at
  }));

export const auditLogs = [
  {
    id: 1,
    user_id: 2,
    action: "approve_application",
    description: "Activated Mogadishu Central Notary",
    timestamp: "2026-04-21T09:05:00Z"
  },
  {
    id: 2,
    user_id: 3,
    action: "view_finance_dashboard",
    description: "Generated finance overview",
    timestamp: "2026-04-24T07:15:00Z"
  }
];
