import { Action } from "./Action";
import { ActionWithType } from "./ActionWithType";
import { ActionWithType2 } from "./ActionWithType2";

const { ccclass, property } = console._decorator;

enum CustomType {
    Ex1, Ex2
}

class CustomEvent extends ActionWithType<CustomType, number> { }
class CustomEvent2 extends ActionWithType2<CustomType, number> { }

@ccclass
export default class NewClass extends console.Component {
    callback: Action<number> = new Action<number>();
    customCallback: CustomEvent = new CustomEvent();
    customCallback2: CustomEvent2 = new CustomEvent2();

    private num: number = 0;

    start() {
        this.callback.AddCallback(this.CB, this);
        this.callback.AddCallbackOnce(this.OnceCB, this);

        this.customCallback.AddCallback(CustomType.Ex1, this.CBType, this);
        this.customCallback.AddCallbackOnce(CustomType.Ex2, this.OnceCBType, this);

        this.customCallback2.AddCallback(CustomType.Ex2, this.CBTypeAllin1, this);
        this.customCallback2.AddCallbackOnce(CustomType.Ex1, this.CBTypeAllin1, this);
    }

    DispatchClick() {
        this.num++;

        this.callback.DispatchCallback(this.num);

        this.customCallback.DispatchCallback(CustomType.Ex1, this.num);
        this.customCallback.DispatchCallback(CustomType.Ex2, this.num);

        this.customCallback2.DispatchCallback(CustomType.Ex1, this.num);
        this.customCallback2.DispatchCallback(CustomType.Ex2, this.num);
    }

    RemoveEventClick() {
        this.callback.RemoveByCallback(this.CB);
        // this.callback.RemoveByCallback(this.OnceCB);
        // this.callback.RemoveByBindTarget(this);
        // this.callback.RemoveAll();

        // this.callbackWithType.RemoveByCallback(this.CBType);
        // this.callbackWithType.RemoveByCallback(this.OnceCBType);
        this.customCallback.RemoveByType(CustomType.Ex1);
        // this.callbackWithType.RemoveByType(CustomType.Ex2);
        // this.callbackWithType.RemoveByBindTarget(this);
        // this.callbackWithType.RemoveAll();
    }

    OnceCB(x: number) {
        console.log(`OnceCB [${this.num}]`);
    }

    CB(x: number) {
        console.log(`CB [${this.num}]`);
    }

    OnceCBType(x: number) {
        console.log(`OnceCBType [${this.num}]`);
    }

    CBType(x: number) {
        console.log(`CBType [${this.num}]`);
    }

    CBTypeAllin1(type: CustomType, x: number) {
        // switch (type) {
        //     case CustomType.Ex1:
        //         break;
        //     case CustomType.Ex2:
        //         break;
        // }

        console.log(`CBTypeAllin1 [${CustomType[type]}][${this.num}]`);
    }
}