/*
 * This file is generated by jOOQ.
 */
package ru.micord.webbpm.ervu.business_metrics.db_beans.actualization.tables;


import java.math.BigDecimal;
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.SQLDataType;
import org.jooq.impl.TableImpl;

import ru.micord.webbpm.ervu.business_metrics.db_beans.actualization.Actualization;
import ru.micord.webbpm.ervu.business_metrics.db_beans.actualization.tables.records.ViewAppReasonRecord;


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

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of <code>actualization.view_app_reason</code>
     */
    public static final ViewAppReason VIEW_APP_REASON = new ViewAppReason();

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

    /**
     * The column <code>actualization.view_app_reason.app_reason_id</code>.
     */
    public final TableField<ViewAppReasonRecord, Long> APP_REASON_ID = createField(DSL.name("app_reason_id"), SQLDataType.BIGINT, this, "");

    /**
     * The column
     * <code>actualization.view_app_reason.percent_place_of_stay</code>.
     */
    public final TableField<ViewAppReasonRecord, BigDecimal> PERCENT_PLACE_OF_STAY = createField(DSL.name("percent_place_of_stay"), SQLDataType.NUMERIC, this, "");

    /**
     * The column <code>actualization.view_app_reason.percent_work</code>.
     */
    public final TableField<ViewAppReasonRecord, BigDecimal> PERCENT_WORK = createField(DSL.name("percent_work"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>actualization.view_app_reason.percent_place_of_study</code>.
     */
    public final TableField<ViewAppReasonRecord, BigDecimal> PERCENT_PLACE_OF_STUDY = createField(DSL.name("percent_place_of_study"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>actualization.view_app_reason.percent_family_status</code>.
     */
    public final TableField<ViewAppReasonRecord, BigDecimal> PERCENT_FAMILY_STATUS = createField(DSL.name("percent_family_status"), SQLDataType.NUMERIC, this, "");

    /**
     * The column <code>actualization.view_app_reason.percent_education</code>.
     */
    public final TableField<ViewAppReasonRecord, BigDecimal> PERCENT_EDUCATION = createField(DSL.name("percent_education"), SQLDataType.NUMERIC, this, "");

    /**
     * The column <code>actualization.view_app_reason.percent_renaming</code>.
     */
    public final TableField<ViewAppReasonRecord, BigDecimal> PERCENT_RENAMING = createField(DSL.name("percent_renaming"), SQLDataType.NUMERIC, this, "");

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

    private ViewAppReason(Name alias, Table<ViewAppReasonRecord> aliased, Field<?>[] parameters, Condition where) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.view("""
        create view "view_app_reason" as  SELECT app_reason.app_reason_id,
         COALESCE(round((((app_reason.count_place_of_stay)::numeric * (100)::numeric) / NULLIF((((((((app_reason.count_place_of_stay + app_reason.count_work) + app_reason.count_place_of_study) + app_reason.count_family_status) + app_reason.count_education) + app_reason.count_education) + app_reason.count_renaming))::numeric, (0)::numeric))), (0)::numeric) AS percent_place_of_stay,
         COALESCE(round((((app_reason.count_work)::numeric * (100)::numeric) / NULLIF((((((((app_reason.count_place_of_stay + app_reason.count_work) + app_reason.count_place_of_study) + app_reason.count_family_status) + app_reason.count_education) + app_reason.count_education) + app_reason.count_renaming))::numeric, (0)::numeric))), (0)::numeric) AS percent_work,
         COALESCE(round((((app_reason.count_place_of_study)::numeric * (100)::numeric) / NULLIF((((((((app_reason.count_place_of_stay + app_reason.count_work) + app_reason.count_place_of_study) + app_reason.count_family_status) + app_reason.count_education) + app_reason.count_education) + app_reason.count_renaming))::numeric, (0)::numeric))), (0)::numeric) AS percent_place_of_study,
         COALESCE(round((((app_reason.count_family_status)::numeric * (100)::numeric) / NULLIF((((((((app_reason.count_place_of_stay + app_reason.count_work) + app_reason.count_place_of_study) + app_reason.count_family_status) + app_reason.count_education) + app_reason.count_education) + app_reason.count_renaming))::numeric, (0)::numeric))), (0)::numeric) AS percent_family_status,
         COALESCE(round((((app_reason.count_education)::numeric * (100)::numeric) / NULLIF((((((((app_reason.count_place_of_stay + app_reason.count_work) + app_reason.count_place_of_study) + app_reason.count_family_status) + app_reason.count_education) + app_reason.count_education) + app_reason.count_renaming))::numeric, (0)::numeric))), (0)::numeric) AS percent_education,
         COALESCE(round((((app_reason.count_renaming)::numeric * (100)::numeric) / NULLIF((((((((app_reason.count_place_of_stay + app_reason.count_work) + app_reason.count_place_of_study) + app_reason.count_family_status) + app_reason.count_education) + app_reason.count_education) + app_reason.count_renaming))::numeric, (0)::numeric))), (0)::numeric) AS percent_renaming
        FROM actualization.app_reason;
        """), where);
    }

    /**
     * Create an aliased <code>actualization.view_app_reason</code> table
     * reference
     */
    public ViewAppReason(String alias) {
        this(DSL.name(alias), VIEW_APP_REASON);
    }

    /**
     * Create an aliased <code>actualization.view_app_reason</code> table
     * reference
     */
    public ViewAppReason(Name alias) {
        this(alias, VIEW_APP_REASON);
    }

    /**
     * Create a <code>actualization.view_app_reason</code> table reference
     */
    public ViewAppReason() {
        this(DSL.name("view_app_reason"), null);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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