import {ModelConditionUtil, ModelConditionUtilImpl, FieldUtil, TableUtilImpl, IdType, BasicFieldUtil, JoinTable, SubTable } from 'model-util'
import {Container, Singleton} from 'typescript-ioc' 
import * as Knex from 'knex' 

import {BMVersion,BMVersionMU} from './BMVersion' 
import {SysUser,SysUserMU} from './SysUser' 


/**
 * @author Keytop midend auto generate
 * @version 1.0
 * @date 2020-06-02 13:51
 */
interface BMModelProject{
    /**
    * 应用ID
    * @type { string }
    */
    appId?: string;
    /**
    * 代码
    * @type { string }
    */
    code?: string;
    /**
    * 创建时间
    * @type { Date }
    */
    createTime?: Date;
    /**
    * 创建人ID
    * @type { string }
    */
    createUserId?: string;
    /**
    * 描述
    * @type { string }
    */
    description?: string;
    /**
    * 主键
    * @type { string }
    */
    id?: string;
    /**
    * 包名
    * @type { string }
    */
    packageName?: string;
    /**
    * 微服务项目ID
    * @type { string }
    */
    pid?: string;
    /**
    * 服务中心ID
    * @type { string }
    */
    serviceCenterId?: string;
    /**
    * 更新时间
    * @type { Date }
    */
    updateTime?: Date;
    /**
    * 修改人ID
    * @type { string }
    */
    updateUserId?: string;
    /**
    * 子表 BMVersion 
    * @type { BMVersion[] }
    */
    bMVersion:BMVersion[];
    /**
    * extend field in SysUser
    * 姓名
    * @type { string }
    */
    createUser?: string;
    /**
    * extend field in SysUser
    * 姓名
    * @type { string }
    */
    updateUser?: string;
}
interface BMModelProjectMCU extends ModelConditionUtil<BMModelProjectMCU>{
    APP_ID:FieldUtil<BMModelProjectMCU>;
    CODE:FieldUtil<BMModelProjectMCU>;
    CREATE_TIME:FieldUtil<BMModelProjectMCU>;
    CREATE_USER_ID:FieldUtil<BMModelProjectMCU>;
    DESCRIPTION:FieldUtil<BMModelProjectMCU>;
    ID:FieldUtil<BMModelProjectMCU>;
    PACKAGE_NAME:FieldUtil<BMModelProjectMCU>;
    PID:FieldUtil<BMModelProjectMCU>;
    SERVICE_CENTER_ID:FieldUtil<BMModelProjectMCU>;
    UPDATE_TIME:FieldUtil<BMModelProjectMCU>;
    UPDATE_USER_ID:FieldUtil<BMModelProjectMCU>;
}

class BMModelProjectMCUImpl extends ModelConditionUtilImpl<BMModelProjectMCUImpl> implements BMModelProjectMCU{ 
    newInstance(): BMModelProjectMCUImpl {
        return new BMModelProjectMCUImpl();
    } 
    get APP_ID(): FieldUtil<BMModelProjectMCU>{  
        return new FieldUtil('APP_ID','appId','应用ID', this);
    }
    get CODE(): FieldUtil<BMModelProjectMCU>{  
        return new FieldUtil('CODE','code','代码', this);
    }
    get CREATE_TIME(): FieldUtil<BMModelProjectMCU>{  
        return new FieldUtil('CREATE_TIME','createTime','创建时间', this);
    }
    get CREATE_USER_ID(): FieldUtil<BMModelProjectMCU>{  
        return new FieldUtil('CREATE_USER_ID','createUserId','创建人ID', this);
    }
    get DESCRIPTION(): FieldUtil<BMModelProjectMCU>{  
        return new FieldUtil('DESCRIPTION','description','描述', this);
    }
    get ID(): FieldUtil<BMModelProjectMCU>{  
        return new FieldUtil('ID','id','主键', this);
    }
    get PACKAGE_NAME(): FieldUtil<BMModelProjectMCU>{  
        return new FieldUtil('PACKAGE_NAME','packageName','包名', this);
    }
    get PID(): FieldUtil<BMModelProjectMCU>{  
        return new FieldUtil('PID','pid','微服务项目ID', this);
    }
    get SERVICE_CENTER_ID(): FieldUtil<BMModelProjectMCU>{  
        return new FieldUtil('SERVICE_CENTER_ID','serviceCenterId','服务中心ID', this);
    }
    get UPDATE_TIME(): FieldUtil<BMModelProjectMCU>{  
        return new FieldUtil('UPDATE_TIME','updateTime','更新时间', this);
    }
    get UPDATE_USER_ID(): FieldUtil<BMModelProjectMCU>{  
        return new FieldUtil('UPDATE_USER_ID','updateUserId','修改人ID', this);
    }
     get CREATE_USER(): BasicFieldUtil{  
        return new BasicFieldUtil('createUser','姓名');
    }
     get UPDATE_USER(): BasicFieldUtil{  
        return new BasicFieldUtil('updateUser','姓名');
    }
}

@Singleton 
class BMModelProjectMU extends TableUtilImpl<BMModelProjectMCU,BMModelProject>{ 
    tableName  = 'bm_model_project';
    tableFields  = ['app_id','code','create_time','create_user_id','description','id','package_name','pid','service_center_id','update_time','update_user_id'];
    modelFields  = ['appId','code','createTime','createUserId','description','id','packageName','pid','serviceCenterId','updateTime','updateUserId','createUser','updateUser'];
    modelIdFields  = ['id'];
    tableIdFields  = ['id'];
    idType = IdType.CUSTOM;
    joinTables = [{
            joinByDefault: true,
            foreignKeyFields: [BMModelProjectMU.UPDATE_USER_ID],
            joinIdFields: [SysUserMU.ID],
            getTableUtil: ()=>{
                return Container.get(SysUserMU);
            },
            fields: [
                {
                    fieldUtil: SysUserMU.NAME,
                    alias: 'createUser'
                }
            ]

        } as JoinTable

        ,{
            joinByDefault: false,
            foreignKeyFields: [BMModelProjectMU.CREATE_USER_ID],
            joinIdFields: [SysUserMU.ID],
            getTableUtil: ()=>{
                return Container.get(SysUserMU);
            },
            fields: [
                {
                    fieldUtil: SysUserMU.NAME,
                    alias: 'updateUser'
                }
            ]

        } as JoinTable

];
    subTables = [{
            name: 'bMVersion',
            parentIdFields: [BMModelProjectMU.ID],
            foreignKeyFields: [BMVersionMU.BM_PROJECT_ID],
            getTableUtil: ()=>{
                return Container.get(BMVersionMU);
            }
        } as SubTable

];

    constructor() {
        super(Container.get(Knex));
    }
    createModelConditionUtil(): BMModelProjectMCU {
        return new BMModelProjectMCUImpl();
    }   

    static get APP_ID(): FieldUtil<BMModelProjectMCU>{ 
        return new FieldUtil('APP_ID','appId','应用ID', new BMModelProjectMCUImpl());
    }
    static get CODE(): FieldUtil<BMModelProjectMCU>{ 
        return new FieldUtil('CODE','code','代码', new BMModelProjectMCUImpl());
    }
    static get CREATE_TIME(): FieldUtil<BMModelProjectMCU>{ 
        return new FieldUtil('CREATE_TIME','createTime','创建时间', new BMModelProjectMCUImpl());
    }
    static get CREATE_USER_ID(): FieldUtil<BMModelProjectMCU>{ 
        return new FieldUtil('CREATE_USER_ID','createUserId','创建人ID', new BMModelProjectMCUImpl());
    }
    static get DESCRIPTION(): FieldUtil<BMModelProjectMCU>{ 
        return new FieldUtil('DESCRIPTION','description','描述', new BMModelProjectMCUImpl());
    }
    static get ID(): FieldUtil<BMModelProjectMCU>{ 
        return new FieldUtil('ID','id','主键', new BMModelProjectMCUImpl());
    }
    static get PACKAGE_NAME(): FieldUtil<BMModelProjectMCU>{ 
        return new FieldUtil('PACKAGE_NAME','packageName','包名', new BMModelProjectMCUImpl());
    }
    static get PID(): FieldUtil<BMModelProjectMCU>{ 
        return new FieldUtil('PID','pid','微服务项目ID', new BMModelProjectMCUImpl());
    }
    static get SERVICE_CENTER_ID(): FieldUtil<BMModelProjectMCU>{ 
        return new FieldUtil('SERVICE_CENTER_ID','serviceCenterId','服务中心ID', new BMModelProjectMCUImpl());
    }
    static get UPDATE_TIME(): FieldUtil<BMModelProjectMCU>{ 
        return new FieldUtil('UPDATE_TIME','updateTime','更新时间', new BMModelProjectMCUImpl());
    }
    static get UPDATE_USER_ID(): FieldUtil<BMModelProjectMCU>{ 
        return new FieldUtil('UPDATE_USER_ID','updateUserId','修改人ID', new BMModelProjectMCUImpl());
    }
    static get CREATE_USER(): BasicFieldUtil{  
        return new BasicFieldUtil('createUser','姓名');
    }
    static get UPDATE_USER(): BasicFieldUtil{  
        return new BasicFieldUtil('updateUser','姓名');
    }

    get APP_ID(): FieldUtil<BMModelProjectMCU>{ 
        return BMModelProjectMU.APP_ID;
    }
    get CODE(): FieldUtil<BMModelProjectMCU>{ 
        return BMModelProjectMU.CODE;
    }
    get CREATE_TIME(): FieldUtil<BMModelProjectMCU>{ 
        return BMModelProjectMU.CREATE_TIME;
    }
    get CREATE_USER_ID(): FieldUtil<BMModelProjectMCU>{ 
        return BMModelProjectMU.CREATE_USER_ID;
    }
    get DESCRIPTION(): FieldUtil<BMModelProjectMCU>{ 
        return BMModelProjectMU.DESCRIPTION;
    }
    get ID(): FieldUtil<BMModelProjectMCU>{ 
        return BMModelProjectMU.ID;
    }
    get PACKAGE_NAME(): FieldUtil<BMModelProjectMCU>{ 
        return BMModelProjectMU.PACKAGE_NAME;
    }
    get PID(): FieldUtil<BMModelProjectMCU>{ 
        return BMModelProjectMU.PID;
    }
    get SERVICE_CENTER_ID(): FieldUtil<BMModelProjectMCU>{ 
        return BMModelProjectMU.SERVICE_CENTER_ID;
    }
    get UPDATE_TIME(): FieldUtil<BMModelProjectMCU>{ 
        return BMModelProjectMU.UPDATE_TIME;
    }
    get UPDATE_USER_ID(): FieldUtil<BMModelProjectMCU>{ 
        return BMModelProjectMU.UPDATE_USER_ID;
    }
     get CREATE_USER(): BasicFieldUtil{  
        return new BasicFieldUtil('createUser','姓名');
    }
     get UPDATE_USER(): BasicFieldUtil{  
        return new BasicFieldUtil('updateUser','姓名');
    }
}
export {BMModelProjectMCU, BMModelProjectMCUImpl, BMModelProject, BMModelProjectMU}
