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


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

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of <code>metrics.view_incidents_closed</code>
     */
    public static final ViewIncidentsClosed VIEW_INCIDENTS_CLOSED = new ViewIncidentsClosed();

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

    /**
     * The column
     * <code>metrics.view_incidents_closed.incidents_closed_id</code>.
     */
    public final TableField<ViewIncidentsClosedRecord, Long> INCIDENTS_CLOSED_ID = createField(DSL.name("incidents_closed_id"), SQLDataType.BIGINT, this, "");

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

    /**
     * The column
     * <code>metrics.view_incidents_closed.percent_refused_to_archive</code>.
     */
    public final TableField<ViewIncidentsClosedRecord, BigDecimal> PERCENT_REFUSED_TO_ARCHIVE = createField(DSL.name("percent_refused_to_archive"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>metrics.view_incidents_closed.percent_accepted_to_archive</code>.
     */
    public final TableField<ViewIncidentsClosedRecord, BigDecimal> PERCENT_ACCEPTED_TO_ARCHIVE = createField(DSL.name("percent_accepted_to_archive"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>metrics.view_incidents_closed.percent_auto_closed</code>.
     */
    public final TableField<ViewIncidentsClosedRecord, BigDecimal> PERCENT_AUTO_CLOSED = createField(DSL.name("percent_auto_closed"), SQLDataType.NUMERIC, this, "");

    /**
     * The column
     * <code>metrics.view_incidents_closed.percent_manual_closed</code>.
     */
    public final TableField<ViewIncidentsClosedRecord, BigDecimal> PERCENT_MANUAL_CLOSED = createField(DSL.name("percent_manual_closed"), SQLDataType.NUMERIC, this, "");

    /**
     * The column <code>metrics.view_incidents_closed.percent_returned</code>.
     */
    public final TableField<ViewIncidentsClosedRecord, BigDecimal> PERCENT_RETURNED = createField(DSL.name("percent_returned"), SQLDataType.NUMERIC, this, "");

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

    private ViewIncidentsClosed(Name alias, Table<ViewIncidentsClosedRecord> aliased, Field<?>[] parameters, Condition where) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.view("""
        create view "view_incidents_closed" as  SELECT incidents_closed.incidents_closed_id,
         ((((incidents_closed.count_refused_to_archive + incidents_closed.count_accepted_to_archive) + incidents_closed.count_auto_closed) + incidents_closed.count_manual_closed) + incidents_closed.count_returned) AS count_all,
         COALESCE(round((((incidents_closed.count_refused_to_archive)::numeric * (100)::numeric) / NULLIF((((((incidents_closed.count_refused_to_archive + incidents_closed.count_accepted_to_archive) + incidents_closed.count_auto_closed) + incidents_closed.count_manual_closed) + incidents_closed.count_returned))::numeric, (0)::numeric))), (0)::numeric) AS percent_refused_to_archive,
         COALESCE(round((((incidents_closed.count_accepted_to_archive)::numeric * (100)::numeric) / NULLIF((((((incidents_closed.count_refused_to_archive + incidents_closed.count_accepted_to_archive) + incidents_closed.count_auto_closed) + incidents_closed.count_manual_closed) + incidents_closed.count_returned))::numeric, (0)::numeric))), (0)::numeric) AS percent_accepted_to_archive,
         COALESCE(round((((incidents_closed.count_auto_closed)::numeric * (100)::numeric) / NULLIF((((((incidents_closed.count_refused_to_archive + incidents_closed.count_accepted_to_archive) + incidents_closed.count_auto_closed) + incidents_closed.count_manual_closed) + incidents_closed.count_returned))::numeric, (0)::numeric))), (0)::numeric) AS percent_auto_closed,
         COALESCE(round((((incidents_closed.count_manual_closed)::numeric * (100)::numeric) / NULLIF((((((incidents_closed.count_refused_to_archive + incidents_closed.count_accepted_to_archive) + incidents_closed.count_auto_closed) + incidents_closed.count_manual_closed) + incidents_closed.count_returned))::numeric, (0)::numeric))), (0)::numeric) AS percent_manual_closed,
         COALESCE(round((((incidents_closed.count_returned)::numeric * (100)::numeric) / NULLIF((((((incidents_closed.count_refused_to_archive + incidents_closed.count_accepted_to_archive) + incidents_closed.count_auto_closed) + incidents_closed.count_manual_closed) + incidents_closed.count_returned))::numeric, (0)::numeric))), (0)::numeric) AS percent_returned
        FROM metrics.incidents_closed;
        """), where);
    }

    /**
     * Create an aliased <code>metrics.view_incidents_closed</code> table
     * reference
     */
    public ViewIncidentsClosed(String alias) {
        this(DSL.name(alias), VIEW_INCIDENTS_CLOSED);
    }

    /**
     * Create an aliased <code>metrics.view_incidents_closed</code> table
     * reference
     */
    public ViewIncidentsClosed(Name alias) {
        this(alias, VIEW_INCIDENTS_CLOSED);
    }

    /**
     * Create a <code>metrics.view_incidents_closed</code> table reference
     */
    public ViewIncidentsClosed() {
        this(DSL.name("view_incidents_closed"), null);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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