/*
 * This file is generated by jOOQ.
 */
package ervu_secret.ervu_secret.db_beans.information_schema.tables;


import ervu_secret.ervu_secret.db_beans.information_schema.Domains;
import ervu_secret.ervu_secret.db_beans.information_schema.InformationSchema;
import ervu_secret.ervu_secret.db_beans.information_schema.tables.records.UserMappingOptionsRecord;

import java.util.Collection;

import org.jooq.Condition;
import org.jooq.Field;
import org.jooq.Name;
import org.jooq.PlainSQL;
import org.jooq.QueryPart;
import org.jooq.SQL;
import org.jooq.Schema;
import org.jooq.Select;
import org.jooq.Stringly;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableOptions;
import org.jooq.impl.DSL;
import org.jooq.impl.TableImpl;


/**
 * This class is generated by jOOQ.
 */
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class UserMappingOptions extends TableImpl<UserMappingOptionsRecord> {

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of
     * <code>information_schema.user_mapping_options</code>
     */
    public static final UserMappingOptions USER_MAPPING_OPTIONS = new UserMappingOptions();

    /**
     * The class holding records for this type
     */
    @Override
    public Class<UserMappingOptionsRecord> getRecordType() {
        return UserMappingOptionsRecord.class;
    }

    /**
     * The column
     * <code>information_schema.user_mapping_options.authorization_identifier</code>.
     */
    public final TableField<UserMappingOptionsRecord, String> AUTHORIZATION_IDENTIFIER = createField(DSL.name("authorization_identifier"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.user_mapping_options.foreign_server_catalog</code>.
     */
    public final TableField<UserMappingOptionsRecord, String> FOREIGN_SERVER_CATALOG = createField(DSL.name("foreign_server_catalog"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.user_mapping_options.foreign_server_name</code>.
     */
    public final TableField<UserMappingOptionsRecord, String> FOREIGN_SERVER_NAME = createField(DSL.name("foreign_server_name"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.user_mapping_options.option_name</code>.
     */
    public final TableField<UserMappingOptionsRecord, String> OPTION_NAME = createField(DSL.name("option_name"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column
     * <code>information_schema.user_mapping_options.option_value</code>.
     */
    public final TableField<UserMappingOptionsRecord, String> OPTION_VALUE = createField(DSL.name("option_value"), Domains.CHARACTER_DATA.getDataType(), this, "");

    private UserMappingOptions(Name alias, Table<UserMappingOptionsRecord> aliased) {
        this(alias, aliased, (Field<?>[]) null, null);
    }

    private UserMappingOptions(Name alias, Table<UserMappingOptionsRecord> aliased, Field<?>[] parameters, Condition where) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.view("""
        create view "user_mapping_options" as  SELECT um.authorization_identifier,
         um.foreign_server_catalog,
         um.foreign_server_name,
         (opts.option_name)::information_schema.sql_identifier AS option_name,
         (
             CASE
                 WHEN (((um.umuser <> (0)::oid) AND ((um.authorization_identifier)::name = CURRENT_USER)) OR ((um.umuser = (0)::oid) AND pg_has_role((um.srvowner)::name, 'USAGE'::text)) OR ( SELECT pg_authid.rolsuper
                    FROM pg_authid
                   WHERE (pg_authid.rolname = CURRENT_USER))) THEN opts.option_value
                 ELSE NULL::text
             END)::information_schema.character_data AS option_value
        FROM information_schema._pg_user_mappings um,
         LATERAL pg_options_to_table(um.umoptions) opts(option_name, option_value);
        """), where);
    }

    /**
     * Create an aliased <code>information_schema.user_mapping_options</code>
     * table reference
     */
    public UserMappingOptions(String alias) {
        this(DSL.name(alias), USER_MAPPING_OPTIONS);
    }

    /**
     * Create an aliased <code>information_schema.user_mapping_options</code>
     * table reference
     */
    public UserMappingOptions(Name alias) {
        this(alias, USER_MAPPING_OPTIONS);
    }

    /**
     * Create a <code>information_schema.user_mapping_options</code> table
     * reference
     */
    public UserMappingOptions() {
        this(DSL.name("user_mapping_options"), null);
    }

    @Override
    public Schema getSchema() {
        return aliased() ? null : InformationSchema.INFORMATION_SCHEMA;
    }

    @Override
    public UserMappingOptions as(String alias) {
        return new UserMappingOptions(DSL.name(alias), this);
    }

    @Override
    public UserMappingOptions as(Name alias) {
        return new UserMappingOptions(alias, this);
    }

    @Override
    public UserMappingOptions as(Table<?> alias) {
        return new UserMappingOptions(alias.getQualifiedName(), this);
    }

    /**
     * Rename this table
     */
    @Override
    public UserMappingOptions rename(String name) {
        return new UserMappingOptions(DSL.name(name), null);
    }

    /**
     * Rename this table
     */
    @Override
    public UserMappingOptions rename(Name name) {
        return new UserMappingOptions(name, null);
    }

    /**
     * Rename this table
     */
    @Override
    public UserMappingOptions rename(Table<?> name) {
        return new UserMappingOptions(name.getQualifiedName(), null);
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserMappingOptions where(Condition condition) {
        return new UserMappingOptions(getQualifiedName(), aliased() ? this : null, null, condition);
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserMappingOptions where(Collection<? extends Condition> conditions) {
        return where(DSL.and(conditions));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserMappingOptions where(Condition... conditions) {
        return where(DSL.and(conditions));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserMappingOptions where(Field<Boolean> condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public UserMappingOptions where(SQL condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public UserMappingOptions where(@Stringly.SQL String condition) {
        return where(DSL.condition(condition));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public UserMappingOptions where(@Stringly.SQL String condition, Object... binds) {
        return where(DSL.condition(condition, binds));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    @PlainSQL
    public UserMappingOptions where(@Stringly.SQL String condition, QueryPart... parts) {
        return where(DSL.condition(condition, parts));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserMappingOptions whereExists(Select<?> select) {
        return where(DSL.exists(select));
    }

    /**
     * Create an inline derived table from this table
     */
    @Override
    public UserMappingOptions whereNotExists(Select<?> select) {
        return where(DSL.notExists(select));
    }
}
