// 假设这些接口和类型已经定义
interface IBaseFilter {
    EnumPins(): IEnumPins | null;
}

interface IPin {
    QueryDirection(): PinDirection;
    // 这里假设存在释放资源的方法
    release(): void;
}

interface IEnumPins {
    Next(count: number): IPin | null;
}

enum PinDirection {
    // 假设这里定义了具体的方向值
    Input,
    Output
}

class CapHelper {
    static GetPin(filter: IBaseFilter, dir: PinDirection, num: number): IPin | null {
        let pin: IPin | null = null;
        const pinsEnum = filter.EnumPins();

        if (pinsEnum) {
            while ((pin = pinsEnum.Next(1)) !== null) {
                const pinDir = pin.QueryDirection();

                if (pinDir === dir) {
                    if (num === 0) {
                        return pin;
                    }
                    num--;
                }

                pin.release();
                pin = null;
            }
        }

        return null;
    }
}

export default CapHelper;