/*
 * This file is generated by jOOQ.
 */
package ru.micord.webbpm.ervu.business_metrics.db_beans.summonses_list.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.summonses_list.SummonsesList;
import ru.micord.webbpm.ervu.business_metrics.db_beans.summonses_list.tables.records.ViewRecruitOfficeVisitRecord;


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

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of
     * <code>summonses_list.view_recruit_office_visit</code>
     */
    public static final ViewRecruitOfficeVisit VIEW_RECRUIT_OFFICE_VISIT = new ViewRecruitOfficeVisit();

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

    /**
     * The column
     * <code>summonses_list.view_recruit_office_visit.recruit_office_visit_id</code>.
     */
    public final TableField<ViewRecruitOfficeVisitRecord, Long> RECRUIT_OFFICE_VISIT_ID = createField(DSL.name("recruit_office_visit_id"), SQLDataType.BIGINT, this, "");

    /**
     * The column
     * <code>summonses_list.view_recruit_office_visit.count_all</code>.
     */
    public final TableField<ViewRecruitOfficeVisitRecord, Long> COUNT_ALL = createField(DSL.name("count_all"), SQLDataType.BIGINT, this, "");

    /**
     * The column
     * <code>summonses_list.view_recruit_office_visit.percent_visit</code>.
     */
    public final TableField<ViewRecruitOfficeVisitRecord, BigDecimal> PERCENT_VISIT = createField(DSL.name("percent_visit"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>summonses_list.view_recruit_office_visit.percent_not_visit</code>.
     */
    public final TableField<ViewRecruitOfficeVisitRecord, BigDecimal> PERCENT_NOT_VISIT = createField(DSL.name("percent_not_visit"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>summonses_list.view_recruit_office_visit.percent_valid_reason</code>.
     */
    public final TableField<ViewRecruitOfficeVisitRecord, BigDecimal> PERCENT_VALID_REASON = createField(DSL.name("percent_valid_reason"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>summonses_list.view_recruit_office_visit.percent_not_need</code>.
     */
    public final TableField<ViewRecruitOfficeVisitRecord, BigDecimal> PERCENT_NOT_NEED = createField(DSL.name("percent_not_need"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>summonses_list.view_recruit_office_visit.percent_hand_over_not_need</code>.
     */
    public final TableField<ViewRecruitOfficeVisitRecord, BigDecimal> PERCENT_HAND_OVER_NOT_NEED = createField(DSL.name("percent_hand_over_not_need"), SQLDataType.NUMERIC, this, "");

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

    private ViewRecruitOfficeVisit(Name alias, Table<ViewRecruitOfficeVisitRecord> aliased, Field<?>[] parameters, Condition where) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.view("""
        create view "view_recruit_office_visit" as  SELECT t.recruit_office_visit_id,
         t.count_all,
         COALESCE(round((((t.count_visit)::numeric * (100)::numeric) / NULLIF((t.count_all)::numeric, (0)::numeric))), (0)::numeric) AS percent_visit,
         COALESCE(round((((t.count_not_visit)::numeric * (100)::numeric) / NULLIF((t.count_all)::numeric, (0)::numeric))), (0)::numeric) AS percent_not_visit,
         COALESCE(round((((t.count_valid_reason)::numeric * (100)::numeric) / NULLIF((t.count_all)::numeric, (0)::numeric))), (0)::numeric) AS percent_valid_reason,
         COALESCE(round((((t.count_not_need)::numeric * (100)::numeric) / NULLIF((t.count_all)::numeric, (0)::numeric))), (0)::numeric) AS percent_not_need,
         COALESCE(round((((t.count_hand_over_not_need)::numeric * (100)::numeric) / NULLIF((t.count_all)::numeric, (0)::numeric))), (0)::numeric) AS percent_hand_over_not_need
        FROM ( SELECT ((((recruit_office_visit.count_visit + recruit_office_visit.count_not_visit) + recruit_office_visit.count_valid_reason) + recruit_office_visit.count_not_need) + recruit_office_visit.count_hand_over_not_need) AS count_all,
                 recruit_office_visit.recruit_office_visit_id,
                 recruit_office_visit.recruitment_id,
                 recruit_office_visit.update_date,
                 recruit_office_visit.info_date,
                 recruit_office_visit.summonses_reason_id,
                 recruit_office_visit.count_visit,
                 recruit_office_visit.count_not_visit,
                 recruit_office_visit.count_valid_reason,
                 recruit_office_visit.count_not_need,
                 recruit_office_visit.count_hand_over_not_need
                FROM summonses_list.recruit_office_visit) t;
        """), where);
    }

    /**
     * Create an aliased <code>summonses_list.view_recruit_office_visit</code>
     * table reference
     */
    public ViewRecruitOfficeVisit(String alias) {
        this(DSL.name(alias), VIEW_RECRUIT_OFFICE_VISIT);
    }

    /**
     * Create an aliased <code>summonses_list.view_recruit_office_visit</code>
     * table reference
     */
    public ViewRecruitOfficeVisit(Name alias) {
        this(alias, VIEW_RECRUIT_OFFICE_VISIT);
    }

    /**
     * Create a <code>summonses_list.view_recruit_office_visit</code> table
     * reference
     */
    public ViewRecruitOfficeVisit() {
        this(DSL.name("view_recruit_office_visit"), null);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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