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


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

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of
     * <code>registration_change_address.view_change_data_personal_visit</code>
     */
    public static final ViewChangeDataPersonalVisit VIEW_CHANGE_DATA_PERSONAL_VISIT = new ViewChangeDataPersonalVisit();

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

    /**
     * The column
     * <code>registration_change_address.view_change_data_personal_visit.change_data_personal_visit_id</code>.
     */
    public final TableField<ViewChangeDataPersonalVisitRecord, Long> CHANGE_DATA_PERSONAL_VISIT_ID = createField(DSL.name("change_data_personal_visit_id"), SQLDataType.BIGINT, this, "");

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

    /**
     * The column
     * <code>registration_change_address.view_change_data_personal_visit.percent_for_sign</code>.
     */
    public final TableField<ViewChangeDataPersonalVisitRecord, BigDecimal> PERCENT_FOR_SIGN = createField(DSL.name("percent_for_sign"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>registration_change_address.view_change_data_personal_visit.percent_signed</code>.
     */
    public final TableField<ViewChangeDataPersonalVisitRecord, BigDecimal> PERCENT_SIGNED = createField(DSL.name("percent_signed"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>registration_change_address.view_change_data_personal_visit.percent_refused</code>.
     */
    public final TableField<ViewChangeDataPersonalVisitRecord, BigDecimal> PERCENT_REFUSED = createField(DSL.name("percent_refused"), SQLDataType.NUMERIC, this, "");

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

    private ViewChangeDataPersonalVisit(Name alias, Table<ViewChangeDataPersonalVisitRecord> aliased, Field<?>[] parameters, Condition where) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.view("""
        create view "view_change_data_personal_visit" as  SELECT change_data_personal_visit.change_data_personal_visit_id,
         ((change_data_personal_visit.count_for_sign + change_data_personal_visit.count_signed) + change_data_personal_visit.count_refused) AS count_all,
         COALESCE(round((((change_data_personal_visit.count_for_sign)::numeric * (100)::numeric) / NULLIF((((change_data_personal_visit.count_for_sign + change_data_personal_visit.count_signed) + change_data_personal_visit.count_refused))::numeric, (0)::numeric))), (0)::numeric) AS percent_for_sign,
         COALESCE(round((((change_data_personal_visit.count_signed)::numeric * (100)::numeric) / NULLIF((((change_data_personal_visit.count_for_sign + change_data_personal_visit.count_signed) + change_data_personal_visit.count_refused))::numeric, (0)::numeric))), (0)::numeric) AS percent_signed,
         COALESCE(round((((change_data_personal_visit.count_refused)::numeric * (100)::numeric) / NULLIF((((change_data_personal_visit.count_for_sign + change_data_personal_visit.count_signed) + change_data_personal_visit.count_refused))::numeric, (0)::numeric))), (0)::numeric) AS percent_refused
        FROM registration_change_address.change_data_personal_visit;
        """), where);
    }

    /**
     * Create an aliased
     * <code>registration_change_address.view_change_data_personal_visit</code>
     * table reference
     */
    public ViewChangeDataPersonalVisit(String alias) {
        this(DSL.name(alias), VIEW_CHANGE_DATA_PERSONAL_VISIT);
    }

    /**
     * Create an aliased
     * <code>registration_change_address.view_change_data_personal_visit</code>
     * table reference
     */
    public ViewChangeDataPersonalVisit(Name alias) {
        this(alias, VIEW_CHANGE_DATA_PERSONAL_VISIT);
    }

    /**
     * Create a
     * <code>registration_change_address.view_change_data_personal_visit</code>
     * table reference
     */
    public ViewChangeDataPersonalVisit() {
        this(DSL.name("view_change_data_personal_visit"), null);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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