import { C as Connection } from './index.js';

var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
class Customer {
    constructor(connection) {
        this.connection = connection;
    }
    equalizeBalance(customer) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.delete(`customer/${customer}/balance`);
        });
    }
    addBalance(request, customer) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.post(`customer/${customer}/balance`, request);
        });
    }
    setContact(request, customer) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.put(`customer/${customer !== null && customer !== void 0 ? customer : request === null || request === void 0 ? void 0 : request.id}/contact`, request);
        });
    }
    create(request) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.post("customer", request);
        });
    }
    get(customer) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.get(`customer/${customer}`);
        });
    }
    update(request, customer) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.patch(`customer/${customer}`, request);
        });
    }
    list() {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.get("customer/");
        });
    }
    createKey(customer) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.post(`customer/${customer}`, undefined);
        });
    }
    createLink(customer) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.post(`customer/${customer}/link`, undefined);
        });
    }
    viewLink(customer, link) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.get(`customer/${customer}/link/${link}`);
        });
    }
    openLink(customer, link) {
        return __awaiter(this, void 0, void 0, function* () {
            const response = yield this.connection.get(`customer/${customer}/link/${link}`);
            typeof response == "string" && (Connection.key = response);
            return typeof response == "string";
        });
    }
    createMethod(request, customer) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.post(`customer/${customer}/method`, request);
        });
    }
    setMethods(request, customer) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.put(`customer/${customer}/methods`, request);
        });
    }
    retryPayment() {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.put(`retry`, {});
        });
    }
    createSubscription(request, customer) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.post(`customer/${customer}/subscription`, request);
        });
    }
    cancelSubscription(customer, subscription) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.delete(`customer/${customer}/subscription/${subscription}`);
        });
    }
    updateSubscription(request, customer, subscription) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.connection.patch(`customer/${customer}/subscription/${subscription}`, request);
        });
    }
    static open(url, key) {
        const connection = Connection.open(url, key);
        return connection && new Customer(connection);
    }
}

export { Customer };
