import { relations } from "drizzle-orm"; import { date, integer, pgTable, serial, text, timestamp, varchar, decimal, boolean, } from "drizzle-orm/pg-core"; import { vendors } from "./vendors"; // 정규업체 등록 관리 테이블 export const vendorRegularRegistrations = pgTable("vendor_regular_registrations", { id: serial("id").primaryKey(), vendorId: integer("vendor_id").notNull().references(() => vendors.id), status: varchar("status", { length: 50 }).notNull().default("audit_pass"), // audit_pass, approval_ready, pending_approval, registration_completed, registration_failed potentialCode: varchar("potential_code", { length: 20 }), // 잠재코드 majorItems: text("major_items"), // 주요품목 (JSON 형태로 저장) registrationRequestDate: date("registration_request_date"), // 등록요청일 assignedDepartment: varchar("assigned_department", { length: 100 }), // 담당부서 assignedDepartmentCode: varchar("assigned_department_code", { length: 20 }), // 담당부서코드 assignedUser: varchar("assigned_user", { length: 100 }), // 담당자 assignedUserCode: varchar("assigned_user_code", { length: 20 }), // 담당자코드 remarks: text("remarks"), // 비고 // 안전적격성 평가 관련 safetyQualificationContent: text("safety_qualification_content"), // 안전적격성 평가 내용 // GTC Skip 관련 gtcSkipped: boolean("gtc_skipped").notNull().default(false), // GTC Skip 여부 createdAt: timestamp("created_at").defaultNow(), updatedAt: timestamp("updated_at").defaultNow(), }); // 업무담당자 정보 테이블 export const vendorBusinessContacts = pgTable("vendor_business_contacts", { id: serial("id").primaryKey(), vendorId: integer("vendor_id").notNull().references(() => vendors.id), contactType: varchar("contact_type", { length: 20 }).notNull(), // sales, design, delivery, quality, tax_invoice contactName: varchar("contact_name", { length: 100 }).notNull(), // 담당자명 position: varchar("position", { length: 50 }).notNull(), // 직급 department: varchar("department", { length: 100 }).notNull(), // 부서 responsibility: varchar("responsibility", { length: 200 }).notNull(), // 담당업무 email: varchar("email", { length: 255 }).notNull(), // Email createdAt: timestamp("created_at").defaultNow(), updatedAt: timestamp("updated_at").defaultNow(), }); // 추가정보 테이블 export const vendorAdditionalInfo = pgTable("vendor_additional_info", { id: serial("id").primaryKey(), vendorId: integer("vendor_id").notNull().references(() => vendors.id), businessType: varchar("business_type", { length: 50 }), // 사업유형 industryType: varchar("industry_type", { length: 50 }), // 산업유형 companySize: varchar("company_size", { length: 20 }), // 기업규모 revenue: decimal("revenue", { precision: 15, scale: 2 }), // 매출액 factoryEstablishedDate: date("factory_established_date"), // 공장설립일 preferredContractTerms: text("preferred_contract_terms"), // 선호계약조건 createdAt: timestamp("created_at").defaultNow(), updatedAt: timestamp("updated_at").defaultNow(), }); // Relations export const vendorRegularRegistrationsRelations = relations( vendorRegularRegistrations, ({ one }) => ({ vendor: one(vendors, { fields: [vendorRegularRegistrations.vendorId], references: [vendors.id], }), }) ); export const vendorBusinessContactsRelations = relations( vendorBusinessContacts, ({ one }) => ({ vendor: one(vendors, { fields: [vendorBusinessContacts.vendorId], references: [vendors.id], }), }) ); export const vendorAdditionalInfoRelations = relations( vendorAdditionalInfo, ({ one }) => ({ vendor: one(vendors, { fields: [vendorAdditionalInfo.vendorId], references: [vendors.id], }), }) );