import { validate_account_req, validate_register_req, validate_commit_req, validate_close_req, validate_lock_req } from '../../../validators/index.js';
import * as assert from '../../../assert.js';
function request_account_api(client) {
    return async (request) => {
        validate_account_req(request);
        const url = `${client.host}/api/deposit/request`;
        const init = {
            method: 'POST',
            body: JSON.stringify(request),
            headers: { 'content-type': 'application/json' }
        };
        return client.fetcher({ url, init });
    };
}
function register_deposit_api(client) {
    return async (request) => {
        validate_register_req(request);
        const url = `${client.host}/api/deposit/register`;
        const init = {
            method: 'POST',
            body: JSON.stringify(request),
            headers: { 'content-type': 'application/json' }
        };
        return client.fetcher({ url, init });
    };
}
function commit_deposit_api(client) {
    return async (request) => {
        validate_commit_req(request);
        const url = `${client.host}/api/deposit/commit`;
        const init = {
            method: 'POST',
            body: JSON.stringify(request),
            headers: { 'content-type': 'application/json' }
        };
        return client.fetcher({ url, init });
    };
}
function read_deposit_api(client) {
    return async (dpid) => {
        assert.is_hash(dpid);
        const url = `${client.host}/api/deposit/${dpid}`;
        return client.fetcher({ url });
    };
}
function read_deposit_digest_api(client) {
    return async (dpid) => {
        assert.is_hash(dpid);
        const url = `${client.host}/api/deposit/${dpid}/digest`;
        return client.fetcher({ url });
    };
}
function read_deposit_status_api(client) {
    return async (dpid) => {
        assert.is_hash(dpid);
        const url = `${client.host}/api/deposit/${dpid}/status`;
        return client.fetcher({ url });
    };
}
function list_deposit_api(client) {
    return async (pubkey, token) => {
        assert.is_hash(pubkey);
        const url = `${client.host}/api/deposit/list/${pubkey}`;
        const init = {
            method: 'GET',
            headers: { 'Authorization': 'Bearer ' + token }
        };
        return client.fetcher({ url, init });
    };
}
function lock_deposit_api(client) {
    return async (dpid, request) => {
        assert.is_hash(dpid);
        validate_lock_req(request);
        const url = `${client.host}/api/deposit/${dpid}/lock`;
        const init = {
            body: JSON.stringify(request),
            method: 'POST',
            headers: { 'content-type': 'application/json' }
        };
        return client.fetcher({ url, init });
    };
}
function close_deposit_api(client) {
    return async (dpid, request) => {
        assert.is_hash(dpid);
        validate_close_req(request);
        const url = `${client._host}/api/deposit/${dpid}/close`;
        const init = {
            body: JSON.stringify(request),
            headers: { 'content-type': 'application/json' },
            method: 'POST'
        };
        return client.fetcher({ url, init });
    };
}
export default function (client) {
    return {
        request: request_account_api(client),
        register: register_deposit_api(client),
        commit: commit_deposit_api(client),
        digest: read_deposit_digest_api(client),
        status: read_deposit_status_api(client),
        list: list_deposit_api(client),
        read: read_deposit_api(client),
        lock: lock_deposit_api(client),
        close: close_deposit_api(client)
    };
}
