from __future__ import annotations

from dataclasses import dataclass


@dataclass(frozen=True)
class ColumnSpec:
    excel_index: int
    source_header: str
    db_name: str
    kind: str = "text"


@dataclass(frozen=True)
class SheetSpec:
    sheet_name: str
    table_name: str
    columns: tuple[ColumnSpec, ...]


def _column(
    excel_number: int,
    source_header: str,
    db_name: str | None = None,
    kind: str = "text",
) -> ColumnSpec:
    return ColumnSpec(
        excel_index=excel_number - 1,
        source_header=source_header,
        db_name=db_name or source_header,
        kind=kind,
    )


OPEN_MARKET_TENDER_SPEC = SheetSpec(
    sheet_name="公开市场招标数据",
    table_name="公开市场招标数据",
    columns=(
        _column(1, "年份", kind="integer"),
        _column(2, "月份"),
        _column(3, "量化月份", kind="integer"),
        _column(4, "数据ID"),
        _column(5, "来源网站"),
        _column(6, "发布链接"),
        _column(7, "采集时间", kind="timestamp"),
        _column(8, "发布时间", kind="timestamp"),
        _column(9, "标题"),
        _column(10, "正文内容"),
        _column(11, "省"),
        _column(12, "地市"),
        _column(13, "区/县", "区_县"),
        _column(14, "项目编号"),
        _column(15, "预算金额(万元)", "预算金额_万元", "numeric"),
        _column(16, "预算金额分层"),
        _column(17, "招标单位"),
        _column(18, "招标方式"),
        _column(19, "开标时间", kind="timestamp"),
        _column(20, "报名截止时间", kind="timestamp"),
        _column(21, "投标资质"),
        _column(22, "行业"),
        _column(23, "行业二级"),
        _column(24, "行业三级"),
        _column(25, "属地"),
        _column(26, "集团编号"),
        _column(27, "集团十五大行业"),
        _column(28, "归属区域（行政）", "归属区域_行政"),
        _column(29, "归属区域（属地）", "归属区域_属地"),
        _column(30, "分类"),
        _column(31, "是否139客户"),
    ),
)


OPERATOR_WINNING_SPEC = SheetSpec(
    sheet_name="运营商市场中标数据",
    table_name="运营商市场中标数据",
    columns=(
        _column(1, "年份", kind="integer"),
        _column(2, "月份"),
        _column(3, "量化月份", kind="integer"),
        _column(4, "序号"),
        _column(5, "ID"),
        _column(6, "应用场景"),
        _column(7, "招标人"),
        _column(8, "客群"),
        _column(9, "行业"),
        _column(10, "集团十五大行业"),
        _column(11, "项目编号"),
        _column(12, "标题"),
        _column(13, "项目名称"),
        _column(14, "招标链接"),
        _column(15, "中标日期", kind="timestamp"),
        _column(16, "月份", "中标月份"),
        _column(17, "采购内容"),
        _column(18, "预算金额（万元）", "预算金额_万元", "numeric"),
        _column(19, "中标总金额（万元）", "中标总金额_万元", "numeric"),
        _column(20, "电信金额（万元）", "电信金额_万元", "numeric"),
        _column(21, "移动金额（万元）", "移动金额_万元", "numeric"),
        _column(22, "联通金额（万元）", "联通金额_万元", "numeric"),
        _column(23, "广电金额（万元）", "广电金额_万元", "numeric"),
        _column(24, "其他金额（万元）", "其他金额_万元", "numeric"),
        _column(25, "中标单位"),
        _column(26, "运营商"),
        _column(27, "是否多家中标"),
        _column(28, "是否单一来源"),
        _column(29, "项目归属区域"),
        _column(30, "商机归属区域"),
        _column(31, "二级属地"),
        _column(32, "商机编号"),
        _column(33, "全网商机编号"),
        _column(34, "项目编号", "商机项目编号"),
        _column(35, "集团编号"),
        _column(36, "客户经理"),
        _column(37, "招标日期", kind="timestamp"),
        _column(38, "中标链接"),
        _column(39, "是否遗漏商机"),
        _column(40, "大单是否及时跟进"),
        _column(41, "备注"),
        _column(42, "投标情况（商机未捕捉/未参投/竞标失败）", "投标情况商机未捕捉_未参投_竞标失败"),
        _column(43, "是否友商前期存量项目(是/否)", "是否友商前期存量项目"),
        _column(44, "涉及标准产品"),
        _column(45, "涉及解决方案"),
        _column(46, "是否涉及专业公司支撑（集成、铁通等/不涉及）", "是否涉及专业公司支撑"),
        _column(47, "专业公司未支撑原因"),
        _column(48, "专业公司支撑是否有不足"),
        _column(49, "对专业公司的意见点"),
        _column(50, "前期走访及其它动作"),
        _column(51, "标书得分对标分析（商务、技术、其它）", "标书得分对标分析商务_技术_其它"),
        _column(52, "丢标原因说明"),
        _column(53, "一级原因"),
        _column(54, "二级原因"),
        _column(55, "备注说明"),
        _column(56, "延续型证明(网址)", "延续型证明网址"),
        _column(57, "商机前置介入时间", kind="integer"),
        _column(58, "计算月份", kind="integer"),
        _column(59, "N运营商共同中标项目", kind="integer"),
        _column(60, "归属区域（行政）", "归属区域_行政"),
        _column(61, "归属区域（属地）", "归属区域_属地"),
        _column(62, "CT类"),
        _column(63, "客户属性"),
        _column(64, "大区区划"),
    ),
)


ALL_SHEET_SPECS = (OPEN_MARKET_TENDER_SPEC, OPERATOR_WINNING_SPEC)
