/*
 * M15 공사/장치 옥션(역경매) API 타입 — 백엔드 com.zioinfo.kintex.auction.dto.AuctionDtos 와 정합.
 * ★ 자체 모듈: 공유 api/types.ts 를 수정하지 않기 위해 옥션 전용 타입을 여기에 둔다.
 * 봉인 입찰: 응찰자 뷰(RankRow)는 마감 전 타사 금액을 price=null·priceMasked=true 로 마스킹.
 */

export type AuctionTypeLabel = '역경매' | 'RFQ';
export type AuctionStatusLabel = '진행중' | '마감' | '정산중';
export type AwardCriteria = 'lowest' | 'comprehensive';
export type MaterialKind = 'layout' | 'design' | 'boq' | 'aiimage';

export interface Weights {
  price: number;
  reputation: number;
  delivery: number;
}

export interface AuctionSummary {
  id: string;
  eventId: string;
  title: string;
  category: string;
  type: AuctionTypeLabel;
  status: AuctionStatusLabel;
  round: number;
  dday: number;
  bidderCount: number;
  lowestPrice: number | null;
  awardedCompany: string | null;
  finalPrice: number | null;
  materials: string[];
  accent: string;
}

export interface MaterialPackage {
  layoutUrl: string | null;
  designUrl: string | null;
  boqUrl: string | null;
  aiImageUrl: string | null;
}

export interface RankRow {
  rank: number;
  alias: string;
  isMe: boolean;
  isLowest: boolean;
  priceMasked: boolean;
  price: number | null;
}

export interface AuctionDetail {
  id: string;
  eventId: string;
  title: string;
  category: string;
  type: AuctionTypeLabel;
  status: AuctionStatusLabel;
  round: number;
  dday: number;
  deadline: string;
  bidderCount: number;
  lowestPrice: number | null;
  awardCriteria: AwardCriteria;
  weights: Weights;
  materials: string[];
  materialPackage: MaterialPackage;
  sealed: boolean;
  myRank: number | null;
  myPrice: number | null;
  ranking: RankRow[];
  canBid: boolean;
  canViewAward: boolean;
  awardedCompany: string | null;
  finalPrice: number | null;
}

/** 견적서 라인아이템 — 금액=수량×단가는 서버가 재계산(클라 값 불신). */
export interface QuoteLine {
  trade: string;
  material: string;
  qty: number;
  unitPrice: number;
}

export interface BidRequest {
  total?: number;
  leadDays?: number;
  validUntil?: string;
  terms?: string;
  lines?: QuoteLine[];
}

export interface BidResult {
  id: string;
  round: number;
  subtotal: number;
  vat: number;
  total: number;
  grandTotal: number;
  version: number;
  myRank: number | null;
  lowestPrice: number | null;
}

export interface CreateAuctionRequest {
  eventId: string;
  title: string;
  category?: string;
  type?: AuctionTypeLabel | 'reverse' | 'rfq';
  awardCriteria?: AwardCriteria;
  weights?: Weights;
  round?: number;
  deadline: string;
  materialPackageId?: string;
  materials?: string[];
  invitedCompanyIds?: string[];
}

export interface Quote {
  bidId: string;
  companyId: string;
  alias: string;
  subtitle: string;
  recommended: boolean;
  totalPrice: number;
  priceDeltaPct: number;
  isLowestPrice: boolean;
  leadDays: number;
  isShortestLead: boolean;
  reputation: number;
  score: number;
}

export interface RiskBar {
  label: string;
  pct: number;
  tone: string;
}

export interface AwardResult {
  id: string;
  bidId: string;
  companyName: string;
  awardedAt: string;
}

export interface AwardView {
  auctionId: string;
  auctionTitle: string;
  bidderCount: number;
  awardCriteria: AwardCriteria;
  weights: Weights;
  quotes: Quote[];
  riskBars: RiskBar[];
  awarded: AwardResult | null;
}

export interface AwardRequest {
  bidId: string;
  reason: string;
}
