package ru.otus.mobile.config;

public enum TestAccount {
    WISHLISTS("user1us", "user1us", """
            WITH target_user AS (
              SELECT id FROM users WHERE username = ?
            ),
            delete_gifts AS (
              DELETE FROM gifts
              WHERE wish_id IN (SELECT id FROM wishlists WHERE user_id IN (SELECT id FROM target_user))
            ),
            delete_wishlists AS (
              DELETE FROM wishlists WHERE user_id IN (SELECT id FROM target_user)
            )
            SELECT 1;
            """),
    GIFTS("user2us", "user2us", """
            WITH target_user AS (
              SELECT id FROM users WHERE username = ?
            ),
            delete_gifts AS (
              DELETE FROM gifts
              WHERE wish_id IN (SELECT id FROM wishlists WHERE user_id IN (SELECT id FROM target_user))
            ),
            delete_wishlists AS (
              DELETE FROM wishlists WHERE user_id IN (SELECT id FROM target_user)
            )
            SELECT 1;
            """),
    RESERVATION("user3us", "user3us", """
            WITH owner_user AS (
              SELECT id FROM users WHERE username = ?
            ),
            target_user AS (
              SELECT id FROM users WHERE username = ?
            ),
            delete_owner_gifts AS (
              DELETE FROM gifts
              WHERE wish_id IN (SELECT id FROM wishlists WHERE user_id IN (SELECT id FROM owner_user))
            ),
            delete_owner_wishlists AS (
              DELETE FROM wishlists WHERE user_id IN (SELECT id FROM owner_user)
            ),
            delete_target_gifts AS (
              DELETE FROM gifts
              WHERE wish_id IN (SELECT id FROM wishlists WHERE user_id IN (SELECT id FROM target_user))
            ),
            delete_target_wishlists AS (
              DELETE FROM wishlists WHERE user_id IN (SELECT id FROM target_user)
            ),
            owner_wishlist AS (
              INSERT INTO wishlists (id, title, description, user_id)
              SELECT gen_random_uuid(), 'Owner Wishlist', 'Prepared for reservation test', id
              FROM owner_user
              RETURNING id
            )
            INSERT INTO gifts (id, name, description, price, is_reserved, store_url, image_url, wish_id)
            SELECT gen_random_uuid(), 'Owner Gift', 'Prepared for reservation test', 100, false, NULL, NULL, id
            FROM owner_wishlist;
            """);

    private final String username;
    private final String password;
    private final String resetSql;

    TestAccount(String username, String password, String resetSql) {
        this.username = username;
        this.password = password;
        this.resetSql = resetSql;
    }

    public String username() {
        return username;
    }

    public String password() {
        return password;
    }

    public String resetSql() {
        return resetSql;
    }
}
