/*
 * 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.ApplicableRolesRecord;

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 ApplicableRoles extends TableImpl<ApplicableRolesRecord> {

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of
     * <code>information_schema.applicable_roles</code>
     */
    public static final ApplicableRoles APPLICABLE_ROLES = new ApplicableRoles();

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

    /**
     * The column <code>information_schema.applicable_roles.grantee</code>.
     */
    public final TableField<ApplicableRolesRecord, String> GRANTEE = createField(DSL.name("grantee"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column <code>information_schema.applicable_roles.role_name</code>.
     */
    public final TableField<ApplicableRolesRecord, String> ROLE_NAME = createField(DSL.name("role_name"), Domains.SQL_IDENTIFIER.getDataType(), this, "");

    /**
     * The column <code>information_schema.applicable_roles.is_grantable</code>.
     */
    public final TableField<ApplicableRolesRecord, String> IS_GRANTABLE = createField(DSL.name("is_grantable"), Domains.YES_OR_NO.getDataType(), this, "");

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

    private ApplicableRoles(Name alias, Table<ApplicableRolesRecord> aliased, Field<?>[] parameters, Condition where) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.view("""
        create view "applicable_roles" as  SELECT (a.rolname)::information_schema.sql_identifier AS grantee,
          (b.rolname)::information_schema.sql_identifier AS role_name,
          (
              CASE
                  WHEN m.admin_option THEN 'YES'::text
                  ELSE 'NO'::text
              END)::information_schema.yes_or_no AS is_grantable
         FROM ((( SELECT pg_auth_members.member,
                  pg_auth_members.roleid,
                  pg_auth_members.admin_option
                 FROM pg_auth_members
              UNION
               SELECT pg_database.datdba,
                  pg_authid.oid,
                  false
                 FROM pg_database,
                  pg_authid
                WHERE ((pg_database.datname = current_database()) AND (pg_authid.rolname = 'pg_database_owner'::name))) m
           JOIN pg_authid a ON ((m.member = a.oid)))
           JOIN pg_authid b ON ((m.roleid = b.oid)))
        WHERE pg_has_role(a.oid, 'USAGE'::text);
        """), where);
    }

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

    /**
     * Create an aliased <code>information_schema.applicable_roles</code> table
     * reference
     */
    public ApplicableRoles(Name alias) {
        this(alias, APPLICABLE_ROLES);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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