// 假设 IPage 接口定义如下
interface IPage {}

// 假设 TradeModel 类型定义如下
interface TradeModel {}

// 定义一个全局对象来存储附加属性的值
const attachedProperties = new WeakMap<object, { [key: string]: any }>();

function getAttachedProperty<T>(obj: object, propertyName: string): T | undefined {
    const properties = attachedProperties.get(obj);
    return properties?.[propertyName];
}

function setAttachedProperty(obj: object, propertyName: string, value: any) {
    let properties = attachedProperties.get(obj);
    if (!properties) {
        properties = {};
        attachedProperties.set(obj, properties);
    }
    properties[propertyName] = value;
}

export class PageHelper {
    // OwnerPage 附加属性
    static get OwnerPageProperty() { return "OwnerPage"; }
    static GetOwnerPage(d: object): IPage | undefined {
        return getAttachedProperty<IPage>(d, this.OwnerPageProperty);
    }
    static SetOwnerPage(d: object, value: IPage) {
        setAttachedProperty(d, this.OwnerPageProperty, value);
    }

    // ViewStateData 附加属性
    static get ViewStateDataProperty() { return "ViewStateData"; }
    static GetViewStateData(obj: object): Record<string, object> | undefined {
        return getAttachedProperty<Record<string, object>>(obj, this.ViewStateDataProperty);
    }
    static SetViewStateData(obj: object, value: Record<string, object>) {
        setAttachedProperty(obj, this.ViewStateDataProperty, value);
    }

    // TradeModel 附加属性
    static get TradeModelProperty() { return "TradeModel"; }
    static GetTradeModel(obj: object): TradeModel | undefined {
        return getAttachedProperty<TradeModel>(obj, this.TradeModelProperty);
    }
    static SetTradeModel(obj: object, value: TradeModel) {
        setAttachedProperty(obj, this.TradeModelProperty, value);
    }
}