import { Container, Inject } from "typescript-ioc"
import { TyInternalApiClient, SelectOneRequest, ListRequest, ExecuteRequest } from './TyInternalApi'
import * as Entity from './Entity'
import { ParamEmptyError } from "./Errors"

/**
 * SQL通道API客户端类
 */
export default class TySqlApiClient {
    @Inject
    tyInternalApiClient: TyInternalApiClient

    parkId: number;

    async selectOne(sql: string): Promise<any> {
        let request = new SelectOneRequest();
        request.parkId = this.parkId;
        request.sql = sql;

        return await this.tyInternalApiClient.selectOne(request);
    }

    async list(sql: string): Promise<[]> {
        let request = new ListRequest();
        request.parkId = this.parkId;
        request.sql = sql;

        return await this.tyInternalApiClient.list(request);
    }

    async execute(sqlList: string[], openTx?: 0 | 1): Promise<any> {
        let request = new ExecuteRequest();
        request.parkId = this.parkId;
        request.sqlList = sqlList;
        request.openTx = openTx;

        return await this.tyInternalApiClient.execute(request);
    }

    /**
     * 车场端区域信息
     */
    area = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_area`; }

        async find(id: any): Promise<Entity.area> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 车场端区域判断
     */
    area_node = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_area_node`; }

        async find(id: any): Promise<Entity.area_node> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 内部车审核
     */
    audit = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_audit`; }

        async find(id: any): Promise<Entity.audit> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    autotoller = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_autotoller`; }
    }(this);

    /**
     * 数据备份记录
     */
    backup_log = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_backup_log`; }

        async find(id: any): Promise<Entity.backup_log> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 账单主表
     */
    car_bill = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_bill`; }

        async find(id: any): Promise<Entity.car_bill> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = '${id}' LITMIT 1`);
        }
    }(this);

    /**
     * 找零明细表 
     */
    car_bill_change_detail = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_bill_change_detail`; }

        async find(id: any): Promise<Entity.car_bill_change_detail> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = '${id}' LITMIT 1`);
        }

        async getListByBillId(billId: string): Promise<Entity.car_bill_change_detail> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE billId = '${billId}'`);
        }
    }(this);

    /**
     * 抵用券使用表
     */
    car_bill_coupon = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_bill_coupon`; }

        async find(id: any): Promise<Entity.car_bill_coupon> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = '${id}' LITMIT 1`);
        }

        async getListByBillId(billId: string): Promise<Entity.car_bill_coupon> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE billId = '${billId}'`);
        }
    }(this);

    /**
     * 账单明细表
     */
    car_bill_detail = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_bill_detail`; }

        async find(id: any): Promise<Entity.car_bill_detail> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = '${id}' LITMIT 1`);
        }

        async getListByBillId(billId: string): Promise<Entity.car_bill_detail> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE billId = '${billId}'`);
        }
    }(this);

    /**
     * 
     */
    car_bill_order = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_bill_order`; }

        async find(id: any): Promise<Entity.car_bill_order> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = '${id}' LITMIT 1`);
        }

        async getListByBillId(billId: string): Promise<Entity.car_bill_order> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE billId = '${billId}'`);
        }
    }(this);

    /**
     * 
     */
    car_bill_recover = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_bill_recover`; }

        async getListByBillId(billId: string): Promise<Entity.car_bill_recover> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE billId = '${billId}'`);
        }
    }(this);

    /**
     * 
     */
    car_blacklist = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_blacklist`; }

        async find(id: any): Promise<Entity.car_blacklist> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    car_blacklist_modify = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_blacklist_modify`; }

        async find(id: any): Promise<Entity.car_blacklist_modify> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 车辆信息矫正表
     */
    car_correct = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_correct`; }

        async find(id: any): Promise<Entity.car_correct> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 进出车辆图片扩展表
     */
    car_img_ext = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_img_ext`; }

        async find(id: any): Promise<Entity.car_img_ext> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }

        async getListByBillId(billId: string): Promise<Entity.car_img_ext> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE billId = '${billId}'`);
        }
    }(this);

    /**
     * 车辆进出明细表
     */
    car_inout = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_inout`; }

        async find(id: any): Promise<Entity.car_inout> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }

        async getListByBillId(billId: string): Promise<Entity.car_inout> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE billId = '${billId}'`);
        }
    }(this);

    /**
     * 车辆清理审核表  备份被清理车辆信息
     */
    car_leave_audit = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_car_leave_audit`; }

        async getListByBillId(billId: string): Promise<Entity.car_leave_audit> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE billId = '${billId}'`);
        }
    }(this);

    /**
     * 车辆在场表
     */
    carcome = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_carcome`; }

        async find(id: any): Promise<Entity.carcome> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }

        async getListByBillId(billId: string): Promise<Entity.carcome> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE billId = '${billId}'`);
        }
    }(this);

    /**
     * 主卡表内部车
     */
    card = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card`; }

        async find(id: any): Promise<Entity.card> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 内部车审核表
     */
    card_audit = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_audit`; }

        async find(id: any): Promise<Entity.card_audit> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 内部车卡片车辆明细
     */
    card_car = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_car`; }

        async find(id: any): Promise<Entity.card_car> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_car_audit = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_car_audit`; }

        async find(id: any): Promise<Entity.card_car_audit> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_car_blacklist = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_car_blacklist`; }

        async find(id: any): Promise<Entity.card_car_blacklist> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_fee_rule = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_fee_rule`; }

        async find(id: any): Promise<Entity.card_fee_rule> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_log = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_log`; }

        async find(id: any): Promise<Entity.card_log> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_log_audit = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_log_audit`; }

        async find(id: any): Promise<Entity.card_log_audit> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_lot = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_lot`; }

        async find(id: any): Promise<Entity.card_lot> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_lot_area = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_lot_area`; }

        async find(id: any): Promise<Entity.card_lot_area> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_lot_area_audit = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_lot_area_audit`; }

        async find(id: any): Promise<Entity.card_lot_area_audit> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_lot_audit = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_lot_audit`; }

        async find(id: any): Promise<Entity.card_lot_audit> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_temp = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_temp`; }

        async find(id: any): Promise<Entity.card_temp> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_validtime = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_validtime`; }

        async find(id: any): Promise<Entity.card_validtime> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    card_validtime_audit = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_card_validtime_audit`; }

        async find(id: any): Promise<Entity.card_validtime_audit> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    config = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_config`; }

        /**
         * 查找非标配置
         */
        async findNsConfig(name: string): Promise<Entity.config> {
            return await this.outer.selectOne(`${this.getTableName()} WHERE session = 'nsConfig' AND name = '${name}' LIMIT 1`);
        }

        /**
         * 查找非标配置值
         */
        async findNsConfigValue(name: string): Promise<string | null> {
            let config = await this.findNsConfig(name);
            return config?.value;
        }

        /**
         * 获取非标配置列表
         * @param name 可按name前缀匹配
         */
        async getNsConfigList(name?: string): Promise<Entity.config[]> {
            return await this.outer.list(`SELECT * FROM ${this.getTableName()} WHERE session = 'nsConfig' ${name ? `AND name like '${name}%'` : ''}`);
        }
    }(this);

    /**
     * 
     */
    credible_user = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_credible_user`; }

        async getListByBillId(billId: string): Promise<Entity.credible_user> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE billId = '${billId}'`);
        }
    }(this);

    /**
     * 
     */
    device = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_device`; }
    }(this);

    /**
     * 
     */
    device_cfg = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_device_cfg`; }
    }(this);

    /**
     * 
     */
    dict = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_dict`; }

        async find(id: any): Promise<Entity.dict> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 显示屏模板的显示内容
     */
    display_content = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_display_content`; }

        async find(id: any): Promise<Entity.display_content> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 显示屏模板元素
     */
    display_element = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_display_element`; }

        async find(id: any): Promise<Entity.display_element> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 显示屏模板元素标签
     */
    display_element_type = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_display_element_type`; }

        async find(id: any): Promise<Entity.display_element_type> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 显示屏模板
     */
    display_template = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_display_template`; }

        async find(id: any): Promise<Entity.display_template> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    drawback = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_drawback`; }

        async find(id: any): Promise<Entity.drawback> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 退款审核表
     */
    drawback_audit = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_drawback_audit`; }

        async find(id: any): Promise<Entity.drawback_audit> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    fee_available = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_fee_available`; }

        async find(id: any): Promise<Entity.fee_available> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 计费规则时间分组
     */
    fee_date_group = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_fee_date_group`; }

        async find(id: any): Promise<Entity.fee_date_group> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    fee_specialdates = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_fee_specialdates`; }

        async find(id: any): Promise<Entity.fee_specialdates> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    fee_static = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_fee_static`; }

        async find(id: any): Promise<Entity.fee_static> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    fee_type = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_fee_type`; }

        async find(id: any): Promise<Entity.fee_type> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    last_carout = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_last_carout`; }

        async find(id: any): Promise<Entity.last_carout> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 终端缴费设备现金状态表
     */
    machine_cash = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_machine_cash`; }

        async find(id: any): Promise<Entity.machine_cash> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 商家充值记录表
     */
    merchant_recharge = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_merchant_recharge`; }

        async find(id: any): Promise<Entity.merchant_recharge> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    modify_carno = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_modify_carno`; }

        async find(id: any): Promise<Entity.modify_carno> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = '${id}' LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    node = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_node`; }

        async find(id: any): Promise<Entity.node> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    node_control = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_node_control`; }

        async find(id: any): Promise<Entity.node_control> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    node_device = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_node_device`; }
    }(this);

    /**
     * 通道自由流开启日志
     */
    node_free_log = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_node_free_log`; }

        async find(id: any): Promise<Entity.node_free_log> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 车道控制配置表
     */
    node_plan = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_node_plan`; }

        async find(id: any): Promise<Entity.node_plan> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 离线模式报表数据量汇总表
     */
    offline_tab_count = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_offline_tab_count`; }
    }(this);

    /**
     * 
     */
    park = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_park`; }
    }(this);

    /**
     * 预约车表
     */
    parking_booking = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_parking_booking`; }

        async find(id: any): Promise<Entity.parking_booking> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    realtime_data = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_realtime_data`; }
    }(this);

    /**
     * 内部车预约车权限管理表
     */
    role_area = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_role_area`; }

        async find(id: any): Promise<Entity.role_area> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 找车系统同步的区域信息
     */
    search_car_area = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_search_car_area`; }

        async find(id: any): Promise<Entity.search_car_area> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 找车系统区域和系统区域关系
     */
    search_car_area_bind = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_search_car_area_bind`; }

        async find(id: any): Promise<Entity.search_car_area_bind> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    special_car = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_special_car`; }

        async find(id: any): Promise<Entity.special_car> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    tab_allsync_assist = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `t_${this.outer.parkId}_tab_allsync_assist`; }
    }(this);

    /**
     * 
     */
    clear_money = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `tp_${this.outer.parkId}_clear_money`; }

        async find(id: any): Promise<Entity.clear_money> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 终端班次表
     */
    duty_detail = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `tp_${this.outer.parkId}_duty_detail`; }

        async find(id: any): Promise<Entity.duty_detail> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 
     */
    file = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `tp_${this.outer.parkId}_file`; }

        async find(id: any): Promise<Entity.file> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);

    /**
     * 临时表，仅用于车场初始化校验表结构是否初始化成功用的
     */
    init_temp = new class {
        constructor(public outer: TySqlApiClient) { }

        getTableName() { return `tp_${this.outer.parkId}_init_temp`; }

        async find(id: any): Promise<Entity.init_temp> {
            return await this.outer.selectOne(`SELECT * FROM ${this.getTableName()} WHERE id = ${id} LITMIT 1`);
        }
    }(this);
}

/**
 * 生成对应的parkId的TySqlApiClient实例
 * @param parkId 
 * @returns 
 */
export function generateTySqlApiClient(parkId: any) {
    if (!parkId) throw new ParamEmptyError('parkId');

    let tySqlApiClient = Container.get(TySqlApiClient);
    tySqlApiClient.parkId = parkId;

    return tySqlApiClient;
}