// 假设 IEntity 接口定义如下
interface IEntity {
    ChangeToTable(): string[];
    ChangeFromTable(parms: any[]): void;
}

// 定义 CommonFunction 类，实现 ChangeDicToStr 和 ChangeStrToDic 方法
class CommonFunction {
    static ChangeDicToStr(dic: { [key: string]: string }): string {
        return Object.entries(dic).map(([key, value]) => `${key}:${value}`).join(',');
    }

    static ChangeStrToDic(str: string): { [key: string]: string } {
        return str.split(',').reduce((acc, pair) => {
            const [key, value] = pair.split(':');
            if (key && value) {
                acc[key] = value;
            }
            return acc;
        }, {} as { [key: string]: string });
    }
}

export class AttchedFiles implements IEntity {
    // 附件数据
    public Filedata: Uint8Array;
    // 附件信息
    public Fileinfo: { [key: string]: string };
    // ID
    public Id: string;
    // 记录Filedata长度，做附件传递用，不对外公开
    public FiledataLength: number;

    constructor() {
        this.Filedata = new Uint8Array();
        this.Fileinfo = {};
        this.Id = '';
        this.FiledataLength = 0;
    }

    public ChangeToTable(): string[] {
        return [this.Id, CommonFunction.ChangeDicToStr(this.Fileinfo), this.Filedata.length.toString()];
    }

    public ChangeFromTable(parms: any[]): void {
        this.Id = parms[0].toString();
        this.Fileinfo = CommonFunction.ChangeStrToDic(parms[1].toString());
        this.FiledataLength = parseInt(parms[2].toString(), 10);
    }
}