"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var theme_attribute_seeds_exports = {};
__export(theme_attribute_seeds_exports, {
  themeAttributeSeeder: () => themeAttributeSeeder
});
module.exports = __toCommonJS(theme_attribute_seeds_exports);
var import_client = require("@prisma/pg/client");
var import_uuid = require("uuid");
const prisma = new import_client.PrismaClient();
function getCurrentUtcTime() {
  return (/* @__PURE__ */ new Date()).toISOString();
}
const themeAttributes = [
  {
    attribute: "accent_tone_color",
    value: "rgb(97,15,16)",
    description: "Header-bg-color,Button-hover-color,Header-color",
    status_id: 1
  },
  {
    attribute: "sidebar_heading_color",
    value: "rgb(50, 45, 47)",
    description: "Sidebar-heading-color",
    status_id: 1
  },
  {
    attribute: "accent_secondary_color",
    value: "rgb(253,240,240)",
    description: "Table-header-color,Pagination-button-bg-color",
    status_id: 1
  },
  {
    attribute: "sidebar_bg_color",
    value: "rgb(34, 30, 32)",
    description: "Sidebar-bg-color",
    status_id: 1
  },
  {
    attribute: "accent_secondary_tone_color",
    value: "rgb(250, 225, 225)",
    description: "Table-header-action-color",
    status_id: 1
  },
  {
    attribute: "accent_color",
    value: "rgb(122, 18, 20)",
    description: "Button-bg-color,Sidebar-hover-color,Form-base-component-color",
    status_id: 1
  },
  {
    attribute: "sidebar_text_color",
    value: "rgb(255, 255, 255)",
    description: "Sidebar-text-color,Header-text-color,Button-text-color",
    status_id: 1
  }
];
async function themeAttributeSeeder(company_id) {
  try {
    const utcNow = getCurrentUtcTime();
    const adminUser = await prisma.user.findFirst({
      where: { company_id, role: "super_admin" }
    });
    if (!adminUser) {
      console.log(
        `Theme attribute seeder failed: super_admin not found for company_id ${company_id}`
      );
      return false;
    }
    const createdBy = adminUser.id;
    const existingAttributes = await prisma.themeAttributes.findMany({
      where: { company_id, attribute: { in: themeAttributes.map((a) => a.attribute) } }
    });
    const existingAttributeMap = new Map(
      existingAttributes.map((attr) => [attr.attribute, attr])
    );
    const promises = [];
    for (const attr of themeAttributes) {
      const existingAttribute = existingAttributeMap.get(attr.attribute);
      if (existingAttribute) {
        promises.push(
          prisma.themeAttributes.update({
            where: { id: existingAttribute.id },
            data: {
              value: attr.value,
              description: attr.description,
              status_id: attr.status_id,
              updated_by: createdBy,
              updated_at: utcNow
            }
          }).then(
            () => console.log(`Theme attribute updated: ${attr.attribute}`)
          ).catch(
            (err) => console.error(
              `Failed to update theme attribute ${attr.attribute}:`,
              err
            )
          )
        );
      } else {
        promises.push(
          prisma.themeAttributes.create({
            data: {
              uuid: (0, import_uuid.v4)(),
              attribute: attr.attribute,
              value: attr.value,
              description: attr.description,
              status_id: attr.status_id,
              company_id,
              created_by: createdBy,
              updated_by: createdBy,
              created_at: utcNow,
              updated_at: utcNow
            }
          }).then(
            () => console.log(`Theme attribute created: ${attr.attribute}`)
          ).catch(
            (err) => console.error(
              `Failed to create theme attribute ${attr.attribute}:`,
              err
            )
          )
        );
      }
    }
    await Promise.all(promises);
    console.log("Theme attribute seeding completed.");
    return true;
  } catch (error) {
    console.error("Theme attribute seeder failed:", error);
    throw error;
  } finally {
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  themeAttributeSeeder
});
